Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Predict file system events on folder delete
    primarykey
    data
    text
    <p>This is more a question about what's the best practice in implementing this.</p> <p>I have a <code>FileSystemWatcher</code> which should inform me about User's changes on files and folders. Also subdirs are watched. In the same directory my program does also sometimes changes. I don't want the <code>FileSystemWatcher</code> to detect events on these program changes.</p> <p>My first implementation was a list where I can add expected events. When I get a file system event I check the list and ignore it if it's there. This doesn't sound very robust but it seemed to work.</p> <p>Now I detected the real problem:<br /> D: is watched by the <code>FileSystemWatcher</code>.<br /> I have two folders like that: D:\folder1\folder2<br /> Now I want to delete folder1 (with folder2 in it) with my application. So I put D:\folder1 in my delete list. Then I call something like <code>Directory.Delete(@"D:\folder1", true)</code> . Now I notice that folder1 can't be deleted (why ever) over an exception. I remove the delete entry from my list but folder2 was already deleted and I get his FileSystemEvent. So I get a FileSystem event for D:\folder1\folder2. My program thinks now the user has deleted this folder and is doing the wrong things.</p> <p>I had some ideas now:</p> <p>1.) recursively delete the folder by deleting every file and every folder by it's own. With this I get for every subfolder and file an own list entry. I already implemented it but it is very very very slow.</p> <p>2.) Maybe there is a better way to have clever filters in the <code>FileSystemWatcher</code> to make my list obsolete?</p> <p>3.) Maybe it is possible to only delete a directory tree if it's possible to delete everything. So if it fails I still have everything and if not everything is deleted. This seems to be the most elegant solution for me but no idea if this is even possible?</p> <p>4.) Is it possible to exclusively lock all files and folders by my software? If this this went ok it should be possible delete everything with one delete command or somehow like this?</p> <p>I'm also open for other additional solutions.</p> <p>Edit 1 to make it more clear:</p> <p>I only want to "see" user actions on a folder. If I manipulate things from my program in here I don't want to see this events.</p> <p>With my implementation I get events for subfolders if a folder is locked and can't be deleted.</p> <p>It's not so easy to explain in english because I'm no english native speaker ;).</p> <p>Edit 2:</p> <p>5.) Maybe it is possible to filter in <code>FileSystemWatcher</code> all events from a defined process?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload