Reputation: 591
I have a function fire every 2 minutes from a Threading.Timer. The function goes through a directory (hardcoded in) and deletes all .ev1 files in it. This directory is on a server and has a file moved to it every ~2 minutes.
It worked for about a day or so, the directory was empty, or had 1 file in it. Now I went to check it and there's 746 files in it. I put a breakpoint after this line:
String[] Files = System.IO.Directory.GetFiles(MachineDir, WatcherFileType, SearchOption.AllDirectories);
Where MachineDir is the directory I'm looking at (I double checked that the directory string is correct). WatcherFileType is .ev1.
Is there some bug with Directory.GetFiles? or possibly something with running this app for extended periods of time.
Upvotes: 0
Views: 1777
Reputation: 613
Have you tried setting WatcherFileType to "*.ev1"
Also you might want to look into the FileSystemWatcher object which doesn't use polling: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
Upvotes: 4
Reputation: 32817
Look at this extract from MSDN
When the extension is exactly three characters,GetFiles
would return all the extensions that match and that starts with that 3 letter extension.
So,
*.txt
would match hello.txt
,hello.txter
,hello.txtworld
Insted use ?.txt
which would match hello.txt
exactly.
This problem is only with 3 letter extention
So you should use
?.ev1
Upvotes: -1