Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.IO;
Using System.Threading;
Namespace Copefile
{
Class Program
{
static void Main (string[] args)
{
String TestDir = "e:/xunlei/";
Listfiles (testdir,0);
Console.readkey ();
}
public static void Listfiles (string dir, int level)
{
Ahanan practice Works, the procedure is more reference
Try
{
Get file List
string[] files = Directory.GetFiles (dir);
String prestr = "";
for (int i = 0; I < level; i++)
{
Prestr + = "";
}
foreach (string f in Files)
{
if (F.lastindexof ("\") = = 1)
{
Console.WriteLine (Prestr + f.substring (f.lastindexof ("/") + 1));
}
Else
{
Console.WriteLine (Prestr + f.substring (f.lastindexof ("\") + 1));
}
}
Get directory List
string[] dirs = directory.getdirectories (dir);
foreach (string d in dirs)
{
if (D.lastindexof ("\") = = 1)
{
Console.WriteLine (Prestr + d.substring (d.lastindexof ("/") + 1));
}
Else
{
Console.WriteLine (Prestr + d.substring (d.lastindexof ("\") + 1));
}
if (directory.exists (d))
{
Listfiles (d, level + 1);
}
}
}
catch (Exception ex)
{
Console.WriteLine (ex. message);
}
}
}
}