2009-04-07, 11:14
billyad2000 Wrote:Sometimes it seems like the whole program is nothing but a large collection of Try Catch blocks.
LOL. It gets that way sometimes doesn't it? I'm a C# man myself, but I just wouldn't scan hidden folders (which SystemVolumeInformation is)
Code:
private void ScanDirectory(string rootDirectory)
{
DirectoryInfo[] dirs = new DirectoryInfo(rootDirectory).GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
if ((dir.Attributes | FileAttributes.Hidden) != dir.Attributes)
{
// Do scanning and whatever else here
}
}
}
Not sure how this would code in VB, but the principle is the same. If you DO want to search hidden folders, the best way is to put the try->catch inside the foreach loop, rather than around in. It's not elegant but it serves a function. This way, you can just catch the exception and continue the loop.