0

Im writing a simple folder watcher program, I would like to ignore a temp.temp file that gets copied into the folder when a scan is made, so the program will detect anything placed in the folder and ignore the temp.temp file. At the moment I have got the program detecting IMG files to get around the problem.

if(e.FullPath.Contains("IMG"))            
{ 
    MessageBox.Show("You have a Collection Form: " + e.Name);
    Process.Start("explorer.exe", e.FullPath);
}
flayn
  • 5,272
  • 4
  • 48
  • 69
Matt
  • 187
  • 1
  • 4
  • 13

5 Answers5

7

If e is of type FileInfo, then you can use

if(e.FullPath.Contains("IMG") && e.Name.Equals("temp.temp", StringComparison.CurrentCultureIgnoreCase))
{ 
    MessageBox.Show("You have a Collection Form: " + e.Name);
    Process.Start("explorer.exe", e.FullPath);
}
foxy
  • 7,599
  • 2
  • 30
  • 34
2

Try : If(!e.FullPath.EndsWith("temp.temp"))

Piotr Auguscik
  • 3,651
  • 1
  • 22
  • 30
0

So if by 'negate' you mean 'ignore', this should work:

if(Path.GetFileName(e.FullPath) != "temp.temp")            
{ 
    MessageBox.Show("You have a Collection Form: " + e.Name);
    Process.Start("explorer.exe", e.FullPath);
}
Iain Ward
  • 9,850
  • 5
  • 34
  • 41
0

If you want to just ignore "temp.temp" how about an early return?

if (e.Name.Equals("temp.temp", StringComparison.CurrentCultureIgnoreCase))
    return;
Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
0

If you're using a FileSystemWatcher use the constructor described here http://msdn.microsoft.com/en-us/library/0b30akzf.aspx to filter for files you want rather than negate the ones you don't.

Mike Miller
  • 16,195
  • 1
  • 20
  • 27