日期:2014-05-18  浏览次数:21076 次

c#如何让实现搜索本地磁盘文件
请高手回答!!

------解决方案--------------------
string[] files = Directory.GetDirectories("C:\\", "*.jpg", SearchOption.AllDirectories);
 
 
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo di in drives)
{} 
 遍历文件夹
public static void FindFile(string dirPath) //参数dirPath为指定的目录
{
DirectoryInfo Dir = new DirectoryInfo(dirPath);
try
{
foreach (DirectoryInfo d in Dir.GetDirectories())
{
FindFile(Dir + d.ToString() + "\\");
}
foreach (FileInfo f in Dir.GetFiles(""))
{
}
}
catch (Exception e)
{
throw e;
}

}

------解决方案--------------------
C# code

Process compiler = new Process();
compiler.StartInfo.FileName = "cmd.exe";
compiler.StartInfo.Arguments = "/c dir d:\\*.txt /s /l /b > c:\\list.txt";
compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
compiler.EnableRaisingEvents = true;
compiler.Exited += (obj, args) =>
{
    string[] fileNames = System.IO.File.ReadAllLines("c:\\list.txt", Encoding.Default);
    Console.WriteLine(string.Join("\r\n", fileNames));
    compiler.Close();
};
compiler.Start();