0

Possible Duplicate:
C# to loop through folder until it finds the correct files

Is it possible to use c# polling to monitor a folder for "required" files? I am running a batch file which requires certain files to be in the folder. If the files are not there and batch job cancels automatically. I am just wondering if I can use ploling to monitor the folder and once they are available I would like the batch file to continue. Thanks

Community
  • 1
  • 1
Liton Uddin
  • 85
  • 1
  • 11

2 Answers2

7

You could poll a folder (via Directory.EnumerateFiles and similar methods) to look for the existence of files.

However, you might want to consider using FileSystemWatcher. It allows you to directly receive events as files are added or removed from a folder.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • See also: http://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-file-changes – Jon B Dec 18 '12 at 19:57
0

you can use a backgroundworker and check for files existence using:

    if (!System.IO.File.Exists("FullAddressFileName"))
                {
                    //stop batch 

                }
IT Seeker
  • 82
  • 8