C#实现目标路径下文件递归的类
来源:互联网 发布:淘宝客服认证二维码 编辑:程序博客网 时间:2024/04/28 03:50
using System;
using System.IO;
using System.Collections;
namespace DSclub
{
/**//// <summary>
/// DirList 的摘要说明。
/// </summary>
public class DirList
{
private string strInitFilePath;
private bool bFatchAll;
// 构造函数
public DirList()
{
bFatchAll = false;
strInitFilePath = "C://";
}
public DirList(string strFilePath)
{
bFatchAll = false;
strInitFilePath = strFilePath;
}
// 是否递归出所有的文件
public bool RecursionFiles
{
get
{
return bFatchAll;
}
set
{
bFatchAll = value;
}
}
// 取得文件的函数
public ArrayList GetFiles()
{
return GetFiles(strInitFilePath, bFatchAll);
}
public static ArrayList GetFiles(string strPath, bool ResultsAll)
{
ArrayList al = new ArrayList();
// 判断路径是否存在
if(!Directory.Exists(strPath))
{
throw(new ApplicationException("访问的路径" + strPath + "不存在,或者它不是个文件夹。"));
}
string[] temp = Directory.GetFiles(strPath);
foreach(string aFile in temp)
{
al.Add(aFile);
}
// 如果此目录下不存在文件,则把文件夹路径返回,并用///作标识
if(temp.Length == 0)
{
al.Add("///" + strPath);
}
if(ResultsAll)
{
temp = Directory.GetDirectories(strPath);
foreach(string aDir in temp)
{
al.AddRange(GetFiles(aDir, ResultsAll));
}
}
return al;
}
}
}
using System.IO;
using System.Collections;
namespace DSclub
{
/**//// <summary>
/// DirList 的摘要说明。
/// </summary>
public class DirList
{
private string strInitFilePath;
private bool bFatchAll;
// 构造函数
public DirList()
{
bFatchAll = false;
strInitFilePath = "C://";
}
public DirList(string strFilePath)
{
bFatchAll = false;
strInitFilePath = strFilePath;
}
// 是否递归出所有的文件
public bool RecursionFiles
{
get
{
return bFatchAll;
}
set
{
bFatchAll = value;
}
}
// 取得文件的函数
public ArrayList GetFiles()
{
return GetFiles(strInitFilePath, bFatchAll);
}
public static ArrayList GetFiles(string strPath, bool ResultsAll)
{
ArrayList al = new ArrayList();
// 判断路径是否存在
if(!Directory.Exists(strPath))
{
throw(new ApplicationException("访问的路径" + strPath + "不存在,或者它不是个文件夹。"));
}
string[] temp = Directory.GetFiles(strPath);
foreach(string aFile in temp)
{
al.Add(aFile);
}
// 如果此目录下不存在文件,则把文件夹路径返回,并用///作标识
if(temp.Length == 0)
{
al.Add("///" + strPath);
}
if(ResultsAll)
{
temp = Directory.GetDirectories(strPath);
foreach(string aDir in temp)
{
al.AddRange(GetFiles(aDir, ResultsAll));
}
}
return al;
}
}
}
- C#实现目标路径下文件递归的类
- C#实现目标路径下文件递归的类
- C#实现目标路径下文件递归的类
- WinCE下文件的路径
- linux 下文件的路径
- WinCE下文件的路径
- C# 打开指定路径下文件
- 求助:递归地读取一个路径下文件总行数遇到的问题。
- java递归查找某一路径下文件代码
- Python:当前路径下文件的复制
- OC获取folder下文件的路径
- 获取assets目录下文件的路径
- 路径下文件遍历
- windows下文件路径与Linux下文件路径的比较
- C#获取指定路径下文件,并按时间排序
- C#下文件的压缩与解压
- Python 实现一个小功能: 删除某路径下文件及文件夹的脚本
- Python 实现删除某路径下文件及文件夹
- 先留个印记
- 正则表达式识别实现
- 三行两列右列固定左列自适应宽度的CSS
- Gridview:在进入编辑模式后动态添加控件
- Eclipse 使用指南
- C#实现目标路径下文件递归的类
- Lenus兄弟写的寻找真正的入口(OEP)--广义ESP定律
- ubutun 6.06 LTS下用wine运行windows上的股票软件
- GridView Examples for ASP.NET 2.0
- C++ Boost 库文档索引
- 搭建WAP应用开发环境
- WML学习(七)
- Microsoft IIS6.0实现WAP应用
- GET是用来获取某些东西,POST则是用来完成某事.