class Program
{
public static void Show(string dirPath)
{
DirectoryInfo dir = new DirectoryInfo(dirPath);
//Папки
string[] dirs = Directory.GetDirectories(dirPath);
//Файлы
FileInfo[] dirFiles = dir.GetFiles();
for (int i = 0; i < dirFiles.Length; i++)
{
Console.WriteLine(" " + dirFiles[i]);
}
for (int i = 0; i < dirs.Length; i++)
{
Console.WriteLine(dirs[i]);
Show(dirs[i]);
}
}
static void Main(string[] args)
{
Show("D:\\test");
Console.ReadLine();
}
}
public static void Show(string dirPath, int level)
{
...
var sb = new StringBuilder();
sb.Append('\t', level);
sb.Append(dirFiles[i]);
Console.WriteLine(sb);
...
Show(dirs[i], level + 1);
...
}
...
static void Main(string[] args)
{
Show("D:\\test", 0);
...
}
public static int level;
...
public static void Show(string dirPath)
{
...
var sb = new StringBuilder();
sb.Append('\t', level);
sb.Append(dirFiles[i]);
Console.WriteLine(sb);
...
level++;
Show(dirs[i]);
level--;
// очевидно что первый вариант будет попроще и понадежнее
...
}
...
static void Main(string[] args)
{
level = 0;
Show("D:\\test");
...
}