473,743 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileSystemWatch er - distinguish file and folder events?

Hi there,

I am experimenting with the FileSystemWatch er object. I have set the
NotifyFilter as follows:

myFileSystemWat cher.NotifyFilt er = NotifyFilters.S ecurity |
NotifyFilters.C reationTime |
NotifyFilters.L astWrite |
NotifyFilters.S ize |
NotifyFilters.A ttributes |
NotifyFilters.D irectoryName|
NotifyFilters.F ileName;

and am looking for these events:

myFileSystemWat cher.Created / Changed / Deleted / Renamed / Error

My question is, how do I distinguish between a FSW Event being fired by the
creation of a FILE, and being fired by the creation of a FOLDER? I've
looked around in the docs and can't find anything.

Is it simply that files have a ".something " suffix and folders do not?

TIA,

JON

Nov 16 '05 #1
5 9752
Wes
Hello Jon,

Here is what I did to determine if it was a directory or not.

protected void FileCreated(obj ect sender, FileSystemEvent Args e)
{
if (e.ChangeType == WatcherChangeTy pes.Created)
{
if (Directory.Exis ts(e.FullPath))
// Do what you need to do with a directory
else
// Do what you need to do with a file
}
}

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

Hi there,

I am experimenting with the FileSystemWatch er object. I have set the
NotifyFilter as follows:

myFileSystemWat cher.NotifyFilt er = NotifyFilters.S ecurity |

NotifyFilters.C reationTime |

NotifyFilters.L astWrite |
NotifyFilters.S ize |

NotifyFilters.A ttributes |

NotifyFilters.D irectoryName|

NotifyFilters.F ileName;
and am looking for these events:

myFileSystemWat cher.Created / Changed / Deleted / Renamed / Error

My question is, how do I distinguish between a FSW Event being fired
by the creation of a FILE, and being fired by the creation of a
FOLDER? I've looked around in the docs and can't find anything.

Is it simply that files have a ".something " suffix and folders do not?

TIA,

JON


Nov 16 '05 #2
Go to http://www.codeguru.com/Csharp/Cshar...icle.php/c6043

This article showed me how to use FileSystemWatch er. I did refer to the
MSDN library for help as well.

Good luck.
Neal
"Jon Maz" <jo****@surfeuN OSPAM.de> wrote in message
news:O2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi there,

I am experimenting with the FileSystemWatch er object. I have set the
NotifyFilter as follows:

myFileSystemWat cher.NotifyFilt er = NotifyFilters.S ecurity |
NotifyFilters.C reationTime
|
NotifyFilters.L astWrite |
NotifyFilters.S ize |
NotifyFilters.A ttributes |

NotifyFilters.D irectoryName|
NotifyFilters.F ileName;

and am looking for these events:

myFileSystemWat cher.Created / Changed / Deleted / Renamed / Error

My question is, how do I distinguish between a FSW Event being fired by
the
creation of a FILE, and being fired by the creation of a FOLDER? I've
looked around in the docs and can't find anything.

Is it simply that files have a ".something " suffix and folders do not?

TIA,

JON


Nov 16 '05 #3
Hi Wes,

Your workaround's a good idea... Have got it working for Created / Renamed /
Changed, but not for Deleted (presumably for the simple reason that once
something - file or folder - is deleted, Directory.Exist s will return
"false").

Any ideas for distinguishing between a FileDeleted and a FolderDeleted
event?

Cheers,

J

_______________ _______________ _____________

"Wes" <ne********@puz zleware.net> wrote in message
news:OL******** ******@TK2MSFTN GP15.phx.gbl...
Hello Jon,

Here is what I did to determine if it was a directory or not.

protected void FileCreated(obj ect sender, FileSystemEvent Args e)
{
if (e.ChangeType == WatcherChangeTy pes.Created)
{
if (Directory.Exis ts(e.FullPath))
// Do what you need to do with a directory
else
// Do what you need to do with a file
}
}

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

_______________ _______________ _____________
----- Original Message -----
From: "Jon Maz" <jo****@surfeuN OSPAM.de>
Newsgroups:
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.languages. c
sharp
Sent: Tuesday, October 19, 2004 4:20 PM
Subject: FileSystemWatch er - distinguish file and folder events?
Hi there,

I am experimenting with the FileSystemWatch er object. I have set the
NotifyFilter as follows:

myFileSystemWat cher.NotifyFilt er = NotifyFilters.S ecurity |
NotifyFilters.C reationTime |
NotifyFilters.L astWrite |
NotifyFilters.S ize |
NotifyFilters.A ttributes |
NotifyFilters.D irectoryName|
NotifyFilters.F ileName;

and am looking for these events:

myFileSystemWat cher.Created / Changed / Deleted / Renamed / Error

My question is, how do I distinguish between a FSW Event being fired by the
creation of a FILE, and being fired by the creation of a FOLDER? I've
looked around in the docs and can't find anything.

Is it simply that files have a ".something " suffix and folders do not?

TIA,

JON


Nov 16 '05 #4
Wes
Hello Jon,

For my application I didn't have to distinguish between file/dir on the delete event. However I have couple ideas/workarounds that may work.

1) Maybe the e.FullPath ends in a '\' char and if so then you could use that to determine that it is a directory.
2) You could setup Two FileSystemWatch ers, one for Files and one for Directories, ie one with NotifyFilter.Fi leName and the other with NotifyFilter.Di rectoryName

I haven't tried either of these, they are just possible ideas that I'm throwing out there.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

Hi Wes,

Your workaround's a good idea... Have got it working for Created /
Renamed / Changed, but not for Deleted (presumably for the simple
reason that once something - file or folder - is deleted,
Directory.Exist s will return "false").

Any ideas for distinguishing between a FileDeleted and a FolderDeleted
event?

Cheers,

J

_______________ _______________ _____________

"Wes" <ne********@puz zleware.net> wrote in message
news:OL******** ******@TK2MSFTN GP15.phx.gbl... Hello Jon,

Here is what I did to determine if it was a directory or not.

protected void FileCreated(obj ect sender, FileSystemEvent Args e)
{
if (e.ChangeType == WatcherChangeTy pes.Created)
{
if (Directory.Exis ts(e.FullPath))
// Do what you need to do with a directory
else
// Do what you need to do with a file
}
}
HTH
Wes Haggard
http://weblogs.asp.net/whaggard/
_______________ _______________ _____________

----- Original Message -----
From: "Jon Maz" <jo****@surfeuN OSPAM.de>
Newsgroups:
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.lang
uages.c
sharp
Sent: Tuesday, October 19, 2004 4:20 PM
Subject: FileSystemWatch er - distinguish file and folder events?
Hi there,

I am experimenting with the FileSystemWatch er object. I have set the
NotifyFilter as follows:

myFileSystemWat cher.NotifyFilt er = NotifyFilters.S ecurity |


NotifyFilters.C reationTime |

NotifyFilters.L astWrite |
NotifyFilters.S ize |

NotifyFilters.A ttributes |

NotifyFilters.D irectoryName|

NotifyFilters.F ileName;
and am looking for these events:

myFileSystemWat cher.Created / Changed / Deleted / Renamed / Error

My question is, how do I distinguish between a FSW Event being fired
by the creation of a FILE, and being fired by the creation of a
FOLDER? I've looked around in the docs and can't find anything.

Is it simply that files have a ".something " suffix and folders do
not?

TIA,

JON


Nov 16 '05 #5
Hi Wes,

Mmm, I don't think the first idea is gonna work. Here's what I'm getting
for
FileCreated and FolderCreated:

Folder Created: C:\temp\new folder
File Created: C:\temp\new text document.txt

I may have to go down that second route, with two separate FSW's, which
seems a real pain for something this simple...

Thanks for the help!

JON

_______________ _______________ _____________
"Wes" <ne********@puz zleware.net> wrote in message
news:Oj******** ******@tk2msftn gp13.phx.gbl...
Hello Jon,

For my application I didn't have to distinguish between file/dir on the
delete event. However I have couple ideas/workarounds that may work.

1) Maybe the e.FullPath ends in a '\' char and if so then you could use that
to determine that it is a directory.
2) You could setup Two FileSystemWatch ers, one for Files and one for
Directories, ie one with NotifyFilter.Fi leName and the other with
NotifyFilter.Di rectoryName

I haven't tried either of these, they are just possible ideas that I'm
throwing out there.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/
_______________ _______________ _____________

----- Original Message -----
From: "Jon Maz" <jo****@surfeuN OSPAM.de>
Newsgroups:
microsoft.publi c.dotnet.langua ges.csharp,micr osoft.public.do tnet.framework. a
spnet
Sent: Wednesday, October 20, 2004 11:25 AM
Subject: Re: FileSystemWatch er - distinguish file and folder events?
Hi Wes,

Your workaround's a good idea... Have got it working for Created / Renamed /
Changed, but not for Deleted (presumably for the simple reason that once
something - file or folder - is deleted, Directory.Exist s will return
"false").

Any ideas for distinguishing between a FileDeleted and a FolderDeleted
event?

Cheers,

J

_______________ _______________ _____________

"Wes" <ne********@puz zleware.net> wrote in message
news:OL******** ******@TK2MSFTN GP15.phx.gbl...
Hello Jon,

Here is what I did to determine if it was a directory or not.

protected void FileCreated(obj ect sender, FileSystemEvent Args e)
{
if (e.ChangeType == WatcherChangeTy pes.Created)
{
if (Directory.Exis ts(e.FullPath))
// Do what you need to do with a directory
else
// Do what you need to do with a file
}
}

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

_______________ _______________ _____________
----- Original Message -----
From: "Jon Maz" <jo****@surfeuN OSPAM.de>
Newsgroups:
microsoft.publi c.dotnet.framew ork.aspnet,micr osoft.public.do tnet.languages. c
sharp
Sent: Tuesday, October 19, 2004 4:20 PM
Subject: FileSystemWatch er - distinguish file and folder events?
Hi there,

I am experimenting with the FileSystemWatch er object. I have set the
NotifyFilter as follows:

myFileSystemWat cher.NotifyFilt er = NotifyFilters.S ecurity |
NotifyFilters.C reationTime |
NotifyFilters.L astWrite |
NotifyFilters.S ize |
NotifyFilters.A ttributes |
NotifyFilters.D irectoryName|
NotifyFilters.F ileName;

and am looking for these events:

myFileSystemWat cher.Created / Changed / Deleted / Renamed / Error

My question is, how do I distinguish between a FSW Event being fired by the
creation of a FILE, and being fired by the creation of a FOLDER? I've
looked around in the docs and can't find anything.

Is it simply that files have a ".something " suffix and folders do not?

TIA,

JON




Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9117
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try copying a large file into the watched folder, the .Created event is fired off immediately and not when the file is finished copying. I have tried waiting for a certain number of .Changed events to be fired after the initial .Created event, and...
0
1316
by: Lloyd Sheen | last post by:
I have created a FileSystemWatcher application that monitors a set of folder for changes. This works well as a windows app. I have copied the code from the windows app to a windows service and now there are problems. If I perform add/chg/del in the folder, the windows app captures all changes (actually to a degree that I did not know happened - ie. 4 events for an add of a file). The windows service though will not pick up add's to...
1
1821
by: Mike | last post by:
I'm running into a problem where the FSW events report all filenames in lower case. (The directory portion is okay, just the leaf file name is broken.) I found this thread from 6/02 stating as such, and a reply presenting a workaround. However, creating a DirectoryInfo or FileInfo object with the path and asking for the Name or FullName still reports the lower case version, not the correct user case. Any ideas short of opening the...
1
3331
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the documentation states that if more than one file is copied to the folder at the same time, a cache will queue them up for processing, but when I drop 3 files into this folder, only the 1st (sometimes the first two) cause the event to fire. Thanks, Troy
1
4616
by: John Lee | last post by:
Hi, I developed a filewatcher service to monitor file creation on a network drive - 90% time it works fine and from time to time I found out that the newly created file on that network drive does not trigger the event - all I have to do is to restart the service. I kind of suspect the reason is when the target matchine where monitored drive is on gets rebooted, the filesystemwatcher lost its "monioring" capability, is that true? if...
3
1580
by: Jon Maz | last post by:
Hi there, I am experimenting with the FileSystemWatcher object. I have set the NotifyFilter as follows: myFileSystemWatcher.NotifyFilter = NotifyFilters.Security | NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.Attributes |
20
4493
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business logic layer(so far so good and easy).I initialize my class which is using a FileSystemWatcher in my Global.asax and everything works fine.I have found FileSystemWatcher class not very reliable and sometimes it behavies unexpectedly.I'm afriad that...
4
7392
by: Michael | last post by:
Hi, I have a little application that watches a FTP folder. When a file is uploaded, it takes that file and moves it to another folder on the same server. Here are a couple of lines from my C# app: FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Created += new FileSystemEventHandler(OnChanged); My problem is that my folder watcher does not know when the file is finish
1
2678
by: D2 | last post by:
Hi, I have this problem when working with FileSystemWatcher class. I m using one of these objects to watch over a folder. Whenever i big file from another folder to the folder being watched, I get created event and multiple changed events. After the file is copied (fully) i want to read the file and perform some operations on it. Now the issue is, there is no way to find that the file has been copied entirely.
0
8970
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8794
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9272
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8218
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4572
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.