用到的类应该都在System.IO里面。

usingSystem.IO;

1、按类型遍历文件夹下所有文件。

DirectoryInfodirInfo=newDirectoryInfo(path);//类型名不区分大小写FileInfo[]files=dirInfo.GetFiles("*.pdf",SearchOption.AllDirectories);foreach(FileInfofileInfoinfiles){Console.WriteLine(fileInfo.FullName);}

2、遍历文件夹下所有文件。

DirectoryInfodirInfo=newDirectoryInfo(path);FileInfo[]files=dirInfo.GetFiles("*.*",SearchOption.AllDirectories);foreach(FileInfofileInfoinfiles){stringfilename=fileInfo.Name.ToLower();//可在这里筛选多种文件类型if(filename.EndsWith(".jpg")||filename.EndsWith(".png")){Console.WriteLine(fileInfo.FullName);}}

3、判断目录是否存在。

if(!Directory.Exists(path)){Console.WriteLine(path+"notexist");}

4、创建目录。

Directory.CreateDirectory(path);//可创建多级目录

5、根据全路径获取目录名。

Path.GetDirectoryName(fullpath)


*** walker ***