Skip to content

Instantly share code, notes, and snippets.

@huoxudong125
Created August 26, 2015 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huoxudong125/525c574ede46f5842236 to your computer and use it in GitHub Desktop.
Save huoxudong125/525c574ede46f5842236 to your computer and use it in GitHub Desktop.
ShowAllFoldersUnder
using System;
using System.IO;
namespace App
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(@"D:\");
ShowAllFoldersUnder(@"D:\", 0);
Console.Read();
}
private static void ShowAllFoldersUnder(string path, int indent)
{
try
{
if ((File.GetAttributes(path) & FileAttributes.ReparsePoint)
!= FileAttributes.ReparsePoint)
{
foreach (string folder in Directory.GetDirectories(path))
{
Console.WriteLine(
"{0}{1}", new string(' ', indent), Path.GetFileName(folder));
ShowAllFoldersUnder(folder, indent + 2);
}
}
}
catch (UnauthorizedAccessException ex) {
Console.WriteLine(ex.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment