using System;
using System
class ListAllFilesDemo
{
//遍歷所有文件和文件夾
public static void ListFiles(FileSystemInfo info)
{
if (!info
DirectoryInfo dir = info as DirectoryInfo;
//不是目錄
if (dir == null) return;
FileSystemInfo[] files = dir
for (int i =
{
FileInfo file = files[i] as FileInfo;
//是文件
if (file != null)
{
if (file
{
Console
Console
}
}
//對於子目錄
else
ListFiles(files[i]);
}
}
public static void Main()
{
Console
string dir = Console
try
{
ListFiles(new DirectoryInfo(dir));
Console
}
catch (IOException e)
{
Console
}
}
}
網頁形式
string thePath =
thePath = Server
System
System
foreach (System
//路徑全稱
Response
//僅文件名稱
Response
}
From:http://tw.wingwit.com/Article/program/net/201311/12136.html