Testing for empty drives

G

G Dean Blake

dim DriveList as string() = Environment.GetLogicalDrives
gives me a string array of every drive on the system

If I cast any of those strings as a directoryinfo, and it is, for instance,
'A:\' and drive A is empty, I get an exception when it is referenced.

Is there any way to test to see if it will cause an exception before getting
the exception?
Thanks,
G
 
H

Herfried K. Wagner [MVP]

G Dean Blake said:
dim DriveList as string() = Environment.GetLogicalDrives
gives me a string array of every drive on the system

If I cast any of those strings as a directoryinfo, and it is, for
instance, 'A:\' and drive A is empty, I get an exception when it is
referenced.

Is there any way to test to see if it will cause an exception before
getting the exception?

You can try to catch the exception.
 

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