Check Files

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
 
S

Sean Hederman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top