Possible Duplicate:
How can I watch a file system directory to see when files are added to it?
I am creating a console app in c# which one of its functionality is to scan a fix folder path(example c:\FixedFolderA) say every minute and check if a new folders has been created(Example c:\FixedFolderA\NewFolderB).
So several folders will be created under c:\FixedFolderA.
The new folders will have no subdirectories, just files which I will copy to other locations.
I am not sure of the most efficient design to do this and need your help.
I was thinking of this workflow:
- Scan c:\FixedFolderA at the start of the program.
- Store all the sub directories in a list.
- Create a worker process that scans c:\FixedFolderA and check to see if that sub-directory exists in the list. If the directory doesn’t exist perform some action.
My concern is that the umber of sub-directories in c:\FixedFolderA will increase overtime and the program would be traversing all these directories every minute.
Should the routine to check every minute be done with a process?
Can someone please share your ideas with the best design to get me started ?
Thanks .
If you plan to watch a folder for changes, use the
FileSystemWatcherclass.Also, if this console application performs a specific task on its own, perhaps it is best to turn it into a Windows Service.