when i use a file system watcher changed event for a notepad it occurs once,but the event occurs twice for a word pad,please give me the reason.i launch using explorer
A bit Briefly,
I have a file named "xxx.log" it contains some strings,i wrote a filesystemwatcher which will watch this file for size(notifyfilter - size) changed.whenever
i opened the file with notepad the changedevent occurs once,whenevr i do it with wordpad
the event occurs twice what is the reason. i open files using explorer.exe.
how to handle this problem.i need the event once only,is there any way
I think that notepad has no lock/backup file handling. Thus it writes only once to the file - Word and Wordpad work with some temporary files for backup and locking purposes and for that reason they might write twice.
The best way to understand this is to use process monitor from sysinternals. This will show you exactly what is going on.
Related
For a project, I needed some FileSystemWatcher on directories. But I got a weird issue : after having launch the app, I can choose the directories where I want to put FileSystemWatcher; if the explorer.exe isn't open when I start to raise events in a directory, I can open it to do stuff in the watched directory. In this case, handlers are fired, and all works perfectly.
Let's imagine I let the explorer.exe open, and I put a FileSystemWatcher in another directory via my app. From this point, I can't modify anything in this second directory : when I modify / rename a file (there's no error during creation of files. EDIT : and I can modify the new file, change his name, etc...), Windows (note this is not the application, but the OS) throws me an error which means "the process can't access this file because of another process accessing it right now".
Does someone have any idea about this, please ?
EDIT : okay, I'm dumb. I just forgot to close a stream...
I want to detect and log to file Explorer operations such as copy/cut/delete/paste.
I have read about FileSystemWatcher, but I also noticed it has some issues since there is no copy/cut events available which can be confusing with whatever I want to do.
The operating system and FileSystemWatcher object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. If you cut and paste a folder with files into a folder being watched, the FileSystemWatcher object reports only the folder as new, but not its contents because they are essentially only renamed.
FileSystemWatcher is hooking the create file and delete file events to the changed and renamed events which can't really help me to determine if it was made by the user or some another process. Furthermore I cannot be 100% sure what happened to the file whether it was copied or cut etc.
I also need to keep track of the locations "from/to" and the name of file.
Is there some alternative to the FileSystemWatcher that can distinguish between these actions?
I think the FileSystemWatcher would be of use in this scenario. You could use the Changed event, which occurs when a file or directory is changed - like a copy/paste action.
See the MSDN Documentation for this event, and the class itself. Note that there are other events that you can also use for the delete/cut actions.
The events use the FileSystemEventArgs which contains properties for FullPath and Name.
i am doing an application that uses file system watcher and the main aim is to monitor files that are being copied , so i looked at the file system watcher method i found 4 events i can sue , they are change , delete , rename and create , i didn't find the copy event , umm and i'd like to watch specific files and when a user tries to copy the files i prevent him from doing so using the file system watcher method , so in file system watcher is there any method for copying files monitoring that i can use ? , sorry my question may look stupid but this is the first time i use file system watcher and i read about it a lot and almost all people agree about the 4 events that can be used in that class .
There is no operation called copying a file.
Rather, copying is a combination of reading one file and writing another one.
You cannot reliably do this.
You cannot do this with FileSystemWatcher
May be monitor Clipboard and if you find list of files, check location of it
I think you can at least have a notification of who copied the file by using WMI notification. Another option is restricting user access to the folders.
Try this link.
http://technet.microsoft.com/en-us/library/ee176985.aspx#EHAA
Why don't you check that the executable is launched from the usb key at the beginning of your software ? this way the user who copied the file won't be able to launch it even if he copied the exe.
How can I find out that user tries to open a file?
I found some events in Windows API but they just notice that file was opened.
Using FileSystemWatcher you can track various changes on the file, see the filters NotifyFilters-
http://channel9.msdn.com/Forums/TechOff/246319-FileSystemWatcher-for-opening-files
FileSystemWatcher triggers for filestream open
You can also try the below link to know how can your create and use FileSystemWatcher component to monitor the changes made to the file system.
http://www.mstecharticles.com/2012/09/c-monitor-file-system-using.html
I have a filesystemwatcher event which watches the path. The problem is when a bulk of files are downloaded into the path where the filesystemwatcher watches, filecreated occurs first then filedeleted occurs which causes all the file to get delete and never the filecreated occur again.
I want to know how to control this condition of filesystemwatcher handling events for files which are getting downloading. I want only one event filecreated/filechanged after the file is finished downloading. And not any other events when it is downloading.
How to achieve this?
Why don't you tell what exactly you want to do may be a simple console app scheduled to run every few minutes will solve your problem.