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