4

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,

Mahendran
  • 468
  • 8
  • 19
  • test before if these folder exist otherwise create them – ale Apr 13 '15 at 09:28
  • 1
    You're probably better off calling `Directory.CreateDirectory` before watching the folder. Watching every parent folder to check if the child folder exists looks to be more work than simply forcing the directory to exist. – Chrono Apr 13 '15 at 09:33

1 Answers1

1

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.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Can watch fulle directory creation like below new FileSystemWatcher(@"C:\",@"Logs\CustomService\Testing\*.log") – Mahendran Apr 13 '15 at 09:31
  • 2
    No, you can't watch a directory that doesn't (partially) exist. You need to watch the parent directory until the subdirectory you're interested in is created. – CodeCaster Apr 13 '15 at 09:32