读出某一个目录的文件和文件夹
class ExploreFold
{
static void Main(string[] args)
{
ExploreFold ef = new ExploreFold();
string theDirectory = @"D:\phproot";
DirectoryInfo dir = new DirectoryInfo(theDirectory);
ef.ExploreDirectory(dir);
Console.ReadLine();
}
private void ExploreDirectory(DirectoryInfo dir)
{
DirectoryInfo[] directories = dir.GetDirectories();
foreach (DirectoryInfo newDir in directories)
{
Console.WriteLine("目录名字{0}",newDir);
ExploreDirectory(newDir);
}
FileInfo[] filesInDir = dir.GetFiles();
foreach (FileInfo file in filesInDir)
{
Console.WriteLine("文件名字{0}",file.Name);
}
}
}
{
static void Main(string[] args)
{
ExploreFold ef = new ExploreFold();
string theDirectory = @"D:\phproot";
DirectoryInfo dir = new DirectoryInfo(theDirectory);
ef.ExploreDirectory(dir);
Console.ReadLine();
}
private void ExploreDirectory(DirectoryInfo dir)
{
DirectoryInfo[] directories = dir.GetDirectories();
foreach (DirectoryInfo newDir in directories)
{
Console.WriteLine("目录名字{0}",newDir);
ExploreDirectory(newDir);
}
FileInfo[] filesInDir = dir.GetFiles();
foreach (FileInfo file in filesInDir)
{
Console.WriteLine("文件名字{0}",file.Name);
}
}
}