Traversing through Drive C#
It is quite easy to traversing through the Files and Directory in a given drive or folder:
Please let me know if I miss something.
Thanks
Enjoy Coding.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DirectoryIterator
{
class DirectoryTraverser
{
String _Source = String.Empty;
private SortedSet SystemFiles = new SortedSet();
DirectoryTraverser(String source)
{
_Source = source;
this.NoteSystemFiles();
}
private void NoteSystemFiles()
{
SystemFiles.Add("$RECYCLE.BIN");
SystemFiles.Add("System Volume Information");
}
void iterateAll()
{
DirectoryInfo dir = new DirectoryInfo(_Source);
foreach (var file in dir.GetFiles())
{
// Do something with files
}
foreach (var subDir in dir.GetDirectories())
{
if (!SystemFiles.Contains(subDir.Name))
{
// do something with sub dir
}
}
}
}
}
Please let me know if I miss something.
Thanks
Enjoy Coding.
Comments
Post a Comment