Check Files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I need to check that 4 access database files exist and they are not in
use before I can process them.

For example say my files are:

C:\test\data1.mdb
C:\test\data2.mdb
C:\test\data3.mdb
C:\test\data4.mdb

I can use if (File.Exists(dbName)) on each one but is there a more generic
way of doing this with a method, an array or looping through them.

Basically I'm looking to check the files exist, if not show a message
reporting which file is missing. Also, check that the files are not open,
then again show a message if they are. The message will need to ask the user
if they want to carry on processing the other databases or cancel the whole
thing.

Thanks
 
Use DirectoryInfo.GetFiles(), there's an overload that will take a search
pattern ("data*.mdb") and return an array of files, then just loop through
the files returned, looking for gaps.
 
Back
Top