asp.net遍歷目錄文件夾和子目錄所有文件
更新時(shí)間:2008年05月01日 09:40:17 作者:
用asp.net實(shí)現(xiàn)遍歷目錄文件和子目錄的代碼
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace copefile
{
class Program
{
static void Main(string[] args)
{
string testDir = "e:/xunlei/";
listFiles(testDir,0);
Console.ReadKey();
}
public static void listFiles(string dir, int level)
{
//阿會(huì)楠練習(xí)作品,程序多有參考
try
{
//獲取文件列表
string[] files = Directory.GetFiles(dir);
String preStr = "";
for (int i = 0; i < level; i++)
{
preStr += " ";
}
foreach (string f in files)
{
if (f.LastIndexOf("\\") == -1)
{
Console.WriteLine(preStr + f.Substring(f.LastIndexOf("/") + 1));
}
else
{
Console.WriteLine(preStr + f.Substring(f.LastIndexOf("\\") + 1));
}
}
//獲取目錄列表
string[] dirs = Directory.GetDirectories(dir);
foreach (string d in dirs)
{
if (d.LastIndexOf("\\") == -1)
{
Console.WriteLine(preStr + d.Substring(d.LastIndexOf("/") + 1));
}
else
{
Console.WriteLine(preStr + d.Substring(d.LastIndexOf("\\") + 1));
}
if (Directory.Exists(d))
{
listFiles(d, level + 1);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
相關(guān)文章
在ASP.NET中使用Session常見(jiàn)問(wèn)題集錦
在ASP.NET中使用Session常見(jiàn)問(wèn)題集錦...2007-08-08詳解ASP.NET Core實(shí)現(xiàn)強(qiáng)類型Configuration讀取配置數(shù)據(jù)
本篇文章主要介紹了詳解ASP.NET Core實(shí)現(xiàn)強(qiáng)類型Configuration讀取配置數(shù)據(jù) ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05asp.net程序在調(diào)式和發(fā)布之間圖片路徑問(wèn)題的解決方法
圖片顯示的時(shí)候,在VS調(diào)式時(shí)候,地址中有個(gè)虛擬文件名,發(fā)布后則沒(méi)有了.所以會(huì)有圖片顯示叉叉的情況.2009-12-12ASP.NET網(wǎng)站偽靜態(tài)下使用中文URL的方法
中文URL是在URL中直接使用漢字,它的好處是可以使用鏈接地址看起來(lái)非常直觀易懂,偽靜態(tài)的規(guī)則,是在web.config文件中定義的2014-08-08詳解ASP.NET Core WebApi 返回統(tǒng)一格式參數(shù)
這篇文章主要介紹了詳解ASP.NET Core WebApi 返回統(tǒng)一格式參數(shù),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11asp.net實(shí)現(xiàn)導(dǎo)出DataTable數(shù)據(jù)到Word或者Excel的方法
這篇文章主要介紹了asp.net實(shí)現(xiàn)導(dǎo)出DataTable數(shù)據(jù)到Word或者Excel的方法,涉及asp.net操作office文件的相關(guān)技巧,需要的朋友可以參考下2016-08-08