2

I have a windows service that watches a path on my PC . My challenge is that I had issue with service and had to stop it and fix it .Now there are new files in sub directories on the watched path that where not process because the service wasn't running . I want to be able to cut the folder out from the path and paste its and my service should then detect the folder and this part works fine but it doesn't continue and read files inside the folder.

Below is how file watcher is set up

fileSystemWatcher1.Path = filePath;
fileSystemWatcher1.EnableRaisingEvents = true;
fileSystemWatcher1.IncludeSubdirectories = true;
fileSystemWatcher1.InternalBufferSize = fsWatcherBuffer;
fileSystemWatcher1.Created += new 
FileSystemEventHandler(fileSystemWatcher1_Created);
fileSystemWatcher1.Changed += new 
FileSystemEventHandler(fileSystemWatcher1_Changed);
sipho
  • 101
  • 7

1 Answers1

0

I did some experiments with my Windows 10 OS and it seems that moving a subfolder raises only a single Created event for the moved directory, but copy-pasting a subfolder raises Created and Changed events for the subfolder and all of its contents (deeply).

My observations don't match the documentation though:

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.

To be notified that the contents of folders have been moved or copied into a watched folder, provide OnChanged and OnRenamed event handler methods

Also from here:

If a directory is created in the sub tree of the directory you are watching, and IncludeSubdirectories is true, that directory will automatically be watched.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104