473,748 Members | 10,048 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 9753
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
4494
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
8989
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
9537
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
9367
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...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.