求助
用ASP.NET 如何遍历计算机的所有文件 --------------------编程问答-------------------- 这个估计的一时半会完不了。 --------------------编程问答-------------------- 下面的代码示例列出了“c:\”中以字母“c”开头的所有目录和文件。在此示例中,SearchOption 用于指定不搜索所有子目录。
using System;
using System.IO;
class App
{
public static void Main()
{
// Specify the directory you want to manipulate.
string path = @"c:\";
string searchPattern = "c*";
DirectoryInfo di = new DirectoryInfo(path);
DirectoryInfo[] directories =
di.GetDirectories(searchPattern, SearchOption.TopDirectoryOnly);
FileInfo[] files =
di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly);
Console.WriteLine(
"Directories that begin with the letter \"c\" in {0}", path);
foreach (DirectoryInfo dir in directories)
{
Console.WriteLine(
"{0,-25} {1,25}", dir.FullName, dir.LastWriteTime);
}
Console.WriteLine();
Console.WriteLine(
"Files that begin with the letter \"c\" in {0}", path);
foreach (FileInfo file in files)
{
Console.WriteLine(
"{0,-25} {1,25}", file.Name, file.LastWriteTime);
}
} // Main()
} // App()
代码来自msdn:
http://msdn.microsoft.com/zh-cn/library/ms143448(v=vs.80).aspx --------------------编程问答--------------------
string newName = "";--------------------编程问答-------------------- 使用asp.net????好像便利服务器上的文件还可以,如果遍历客户端的机器难。。。 --------------------编程问答-------------------- 用递归吧
public string getFile()
{
string path = @"d:\";
foreach (string fileName in System.IO.Directory.GetFiles(path))
{
newName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
}
return path;
}
遍历所有文件干什么呢?
补充:.NET技术 , ASP.NET