-1

I am using FileSystemWatcher to watch on a directory. On delete events I need to take different actions on files and folders. But I didn't find a way as the file/folder was already deleted.

One way can be to check if the file/folder path had any extension to it. but that's not a reliable way.

In Short I want to implement WasFile() method here ->

private static void OnDelete(object source, RenamedEventArgs e)
{
    if(WasFile(e.FullPath))
    {
          Console.WriteLine("Deleted event {0} was a File", e.FullPath);
    }
    //else a folder
}

1 Answers1

1

You could do

if(e.FullPath[e.FullPath.Length]  == '\\')
{
    // directory
}
else
{
    //file
}

Or

if(Directory.Exists(e.FullPath))
{
   // directory
}
else
{
    // file
}
Joe
  • 528
  • 5
  • 19