I\'m writing a program that gets all directories and sub-directories. I\'m using the following code:
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (Dri
After looking for an answer for some time - I decided to write the code on my own.
I'm sharing here the basic idea and not the full code - Take the important part and use it implement it in your code.
Worked for me.
public void directoryCrawl(string startFolder)
{
try
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
/* here you can add "dir" to some kind of list of your choice. */
foreach (System.IO.DirectoryInfo directory in dir.GetDirectories())
{
try
{
directoryCrawl(directory.FullName);
}
catch
{
Console.Writeline("Access denied to: \"" + directory.FullName + "\".");
}
}
}
catch
{
if (!String.IsNullOrEmpty(startFolder))
{
Console.Writeline("Access denied to: \"" + startFolder + "\".");
}
}
return;
}