I spent far too long today thinking about ways to code what at first appears to be a simple C# statement regarding file recursion. I’m building a new class based on code that has been tried and tested, the only difference was that in some scenarios I wish to ignore the root C: drive. In C# the DriveInfo class builds an array … minus any .Remove() or .RemoveAt() methods. I had a nice tidy method that was about as short as it could be but shoehorning this new bit of functionality inside the same method proved more awkward than I had imagined. After poking and prodding this method (and the next method in the recursion chain) I did this …

[source:c-sharp] public static void GetMachinesDirectoryList(bool ignoreC)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if (drive.DriveType == DriveType.Fixed && drive.IsReady == true)
{
if (ignoreC == true && drive.Name.StartsWith(“C”) )
{
}
else
{
ScanDir(drive.ToString());
}
}
}
}
[/source]

A kind of ‘do nothing’ statement, It works!! Although I’m really unsure just how ‘safe’ this code is. I’m having a read up on it and the potential pitfalls. I’m guesing that it will be safe as there is nothing in there to throw any exceptions!!!! (famous last words!).

Using MediaElement
Download FireFox 3 Today!!

Leave a Comment

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.