Reputation: 125
I have a folder(lets call it folder1) where new files are added continously. I maintain a log file (containing file full path and size) for each file present in folder1. This log file I would be using to copy files from folder1 to folder2.
This is a continous process for which I would be writing a windows service, but thats for later.
To start with I am thinking in terms of having a timer/filesystem watcher which will monitor the folder and look up for changes and on the event loop through the file list in folder1 and add the fileinfo(i.e. file path and size) to my log file(which would be a normal .txt file).
My question is it an efficient way of doing this ? Is there any fast or efficient way?
Any feedback or suggestion is appreciated.
Upvotes: 3
Views: 1360
Reputation: 50855
Check out the FileSystemWatcher
class. It's intended to do just what you're looking for.
In particular you're going to want to handle the Created
event. There's a very complete sample on MSDN which shows you how to set that up.
Upvotes: 6