Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a file system watcher. I want to maximize its use. Is it possible that file system watcher can record the event like moving a particular file in one of the folders on the drive that is being watched. Example, "me.txt was moved to E:\New Folder" instead of "me.txt was created at E:\New Folder".. Is it possible? And whenever I create a New Folder, usually Im renaming it so that I can remember. But the file system watcher records something like "New Folder has been created at E:\" followed by "E:\New Folder has been renamed to Hello". Is it possible to just record, "Hello has been created at E:\"? I just really want to learn more about FS Watcher so I hope you guys can help me. Thank you in advance!
Posted

1 solution

The FileSystemWatcher can be used to monitor whether the contents of a folder have been Created, Changed, Deleted or Renamed. You just need to subscribe to any of those events, and you can control what the Watcher does when those events happen.

Here is the MSDN Article on FileSystemWatcher[^]

Hope that helps
 
Share this answer
 
Comments
mitchyblue 12-May-11 5:08am    
I've already done that. I just really want to know if its possible to just report the event "MOVED TO" because I am moving a file to a particular folder and the result is it has been reported to be DELETED in its Old Path while it has been CREATED to its New Path? But I just moved the file, I did not delete it nor created it. Thank you.
Wayne Gaylard 12-May-11 5:22am    
What windows does is Delete it from one Folder and Create it in another Folder, and so there is really no concept of 'moving' a File in Windows OS. Sorry.
Dave Kreskowiak 12-May-11 7:23am    
There is no "moving" of a file as far as teh FSW is concerned. All it knows is that a new filename showed up in a folder it is watching, which means the file was created.

"Moving" a file is a term used the by shell (Explorer). It's not one used by the file system.

As for your "new folder" question, the same thing happens. The new folder is "New Folder", then it is renamed. It will not show you that the new folder was "Hello".
senguptaamlan 12-May-11 7:54am    
actually you have already solved the problem.... :)
whenever you get consecutive notification from FileSystemWatcher for the same file for delete and create, then flag it as moved.. :)
mitchyblue 13-May-11 6:56am    
@senguptaamlan- how can i do that? can you give me some example?

@dave and wayne- thank you so much for helping. but if you have learn some possibilities to do that, please let me know. thank you again. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900