5

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,

2
  • test before if these folder exist otherwise create them Commented Apr 13, 2015 at 9: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. Commented Apr 13, 2015 at 9:33

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can watch fulle directory creation like below new FileSystemWatcher(@"C:\",@"Logs\CustomService\Testing*.log")
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.