473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

FileSystemWatcher - distinguish file and folder events?

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 |
NotifyFilters.DirectoryName|
NotifyFilters.FileName;

and am looking for these events:

myFileSystemWatcher.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 18 '05 #1
3 1559
Go to http://www.codeguru.com/Csharp/Cshar...icle.php/c6043

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

Good luck.
Neal
"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:O2****************@TK2MSFTNGP11.phx.gbl...
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 |

NotifyFilters.DirectoryName|
NotifyFilters.FileName;

and am looking for these events:

myFileSystemWatcher.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 18 '05 #2
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.Exists will return
"false").

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

Cheers,

J

___________________________________________

"Wes" <ne********@puzzleware.net> wrote in message
news:OL**************@TK2MSFTNGP15.phx.gbl...
Hello Jon,

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

protected void FileCreated(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Created)
{
if (Directory.Exists(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****@surfeuNOSPAM.de>
Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft .public.dotnet.languages.c
sharp
Sent: Tuesday, October 19, 2004 4:20 PM
Subject: FileSystemWatcher - distinguish file and folder events?
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 |
NotifyFilters.DirectoryName|
NotifyFilters.FileName;

and am looking for these events:

myFileSystemWatcher.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 18 '05 #3
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********@puzzleware.net> wrote in message
news:Oj**************@tk2msftngp13.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 FileSystemWatchers, one for Files and one for
Directories, ie one with NotifyFilter.FileName and the other with
NotifyFilter.DirectoryName

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****@surfeuNOSPAM.de>
Newsgroups:
microsoft.public.dotnet.languages.csharp,microsoft .public.dotnet.framework.a
spnet
Sent: Wednesday, October 20, 2004 11:25 AM
Subject: Re: FileSystemWatcher - 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.Exists will return
"false").

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

Cheers,

J

___________________________________________

"Wes" <ne********@puzzleware.net> wrote in message
news:OL**************@TK2MSFTNGP15.phx.gbl...
Hello Jon,

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

protected void FileCreated(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Created)
{
if (Directory.Exists(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****@surfeuNOSPAM.de>
Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft .public.dotnet.languages.c
sharp
Sent: Tuesday, October 19, 2004 4:20 PM
Subject: FileSystemWatcher - distinguish file and folder events?
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 |
NotifyFilters.DirectoryName|
NotifyFilters.FileName;

and am looking for these events:

myFileSystemWatcher.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 18 '05 #4

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

Similar topics

4
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...
0
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...
1
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...
1
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...
5
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...
1
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...
3
by: Stampede | last post by:
Hi, I write an application which waits for incomming files in a specified directory. I thought, that using the FileSystemWatcher would be the best, as it does exactly what I need. But now I have...
20
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...
4
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#...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...

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.