Search code examples
c#filesystemwatcher

How can i use FileSystemWatcher to watch directory if directory not exist?


can any one help me to solve my problem below. I need to watch the file created inside the folder "C:\Logs\CustomService\Testing". I am using the FileSystemWatcher to watch the files created inside it but how can i watch the folder Testing for the below cases

case1: only contain drive C:\ how can i watch file created inside testing folder ?

case2: only contain following folder C:\Logs how can i watch file created inside testing folder ?

case3: only contain following folder C:\Logs\CustomService, How can i watch file created inside testing folder ?

case4: contian full path C:\Logs\CustomService\Testing , in this case i can use FileSystemWatcher to watch file created inside testing folder

Thanks,


Solution

  • case1: only contain drive C:\

    Watch that directory for a "Logs" directory to be created, go to next case.

    case2: only contain folder C:\Logs

    Watch that directory for a "CustomService" directory to be created, go to next case.

    case3: only contain folder C:\Logs\CustomService

    Watch that directory for a "Testing" directory to be created, go to next case.

    Or, just create the directory.