I'm using System.IO.FileSystemWatcher
to monitor a directory and does things when a file or directory is modified or deleted.
The issue I have is that once a folder is deleted, the Deleted
event is raised, but the argument I get is not useful enough for me to know if a directory or file is deleted.
The argument I get is a path, for example C:\Temp\a
which can be a directory or a file with no extension.
I tried the followings, but they all failed to give me the correct result.
var c = Path.DirectorySeparatorChar.ToString();
var isDir = Path.GetDirectoryName(path) == path.TrimEnd(c.ToCharArray());
and
var isDir =(File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory;