using System;
using SystemIO;
class ListAllFilesDemo
{
//遍历所有文件和文件夹查找指定文件并返回该文件的完整路径
public static void ListFiles(FileSystemInfo info)
{
if (!infoExists) return;
DirectoryInfo dir = info as DirectoryInfo;
//不是目录
if (dir == null) return;
FileSystemInfo[] files = dirGetFileSystemInfos();
for (int i = ; i < filesLength; i++)
{
FileInfo file = files[i] as FileInfo;
//是文件
if (file != null)
{
if (fileNameContains(configincphp))
{
ConsoleWriteLine(fileFullName);
ConsoleReadLine();
}
}
//对于子目录进行递归调用
else
ListFiles(files[i]);
}
}
public static void Main()
{
ConsoleWrite(请输入要查询的目录: );
string dir = ConsoleReadLine();
try
{
ListFiles(new DirectoryInfo(dir));
ConsoleReadLine();
}
catch (IOException e)
{
ConsoleWriteLine(eMessage);
}
}
}
网页形式
string thePath = //Upload/Star/;
thePath = ServerMapPath(thePath);//得到文件绝对路径
SystemIODirectoryInfo d = new SystemIODirectoryInfo(thePath);
SystemIODirectoryInfo[] ds = dGetDirectories(** SystemIOSearchOptionTopDirectoryOnly);
foreach (SystemIODirectoryInfo var in ds) {
//路径全称
ResponseWrite(varFullName + <br/>);//遍历文件夹下面的文件夹
//仅文件名称
ResponseWrite(varName + <br/>);
}