C#

推荐列表 站点导航

当前位置:首页 > 脚本编程 > C# >

C#_c#递归遍历文件夹示例,代码很简单,指定需要递归遍

来源:网络整理  作者:  发布时间:2020-12-19 14:21
c#递归遍历文件夹示例,代码很简单,指定需要递归遍历的文件夹和遍历规则就要可以运行了复制代码 代码如下:/// s...
{
DirectorySecurity _pathSecurity = new DirectorySecurity(_path, AccessControlSections.Access);

代码很简单,指定需要递归遍历的文件夹和遍历规则就要可以运行了
public static void LoopFolder(string pathName, Action<FileInfo> fileRule)
/// <param>需要递归遍历的文件夹</param>
/// <summary>
foreach (FileInfo file in _directoryInfo.GetFiles())

复制代码 代码如下:

{
{
}
if (!_pathSecurity.AreAccessRulesProtected)//文件夹权限是否可访问

复制代码 代码如下:

}
DirectoryInfo _directoryInfo = new DirectoryInfo(_path);
fileRule(file);
_pathQueue.Enqueue(pathName);
/// </summary>



{


if (string.IsNullOrEmpty(pathName))
{
}

/// <param>遍历规则『委托』</param>

}
if (file.Extension.Equals(".xls"))//获取excel类型文件
foreach (DirectoryInfo diChild in _directoryInfo.GetDirectories())
}
Console.WriteLine(string.Format("============{0}==============", file.FullName));

举例使用
/// 递归获取文件夹目录下文件

Queue<string> _pathQueue = new Queue<string>();
_pathQueue.Enqueue(diChild.FullName);
while (_pathQueue.Count > 0)
throw new ArgumentNullException(pathName);

{
CSharpToolV2.LoopFolder(@"C:\Users\Administrator\Downloads\", (FileInfo file) =>
string _path = _pathQueue.Dequeue();
{
}

相关热词: C#

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/c/5639.shtml

最新文章
热门文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

C#_c#递归遍历文件夹示例,代码很简单,指定需要递归遍

2020-12-19 编辑:

{
DirectorySecurity _pathSecurity = new DirectorySecurity(_path, AccessControlSections.Access);

代码很简单,指定需要递归遍历的文件夹和遍历规则就要可以运行了
public static void LoopFolder(string pathName, Action<FileInfo> fileRule)
/// <param>需要递归遍历的文件夹</param>
/// <summary>
foreach (FileInfo file in _directoryInfo.GetFiles())

复制代码 代码如下:

{
{
}
if (!_pathSecurity.AreAccessRulesProtected)//文件夹权限是否可访问

复制代码 代码如下:

}
DirectoryInfo _directoryInfo = new DirectoryInfo(_path);
fileRule(file);
_pathQueue.Enqueue(pathName);
/// </summary>



{


if (string.IsNullOrEmpty(pathName))
{
}

/// <param>遍历规则『委托』</param>

}
if (file.Extension.Equals(".xls"))//获取excel类型文件
foreach (DirectoryInfo diChild in _directoryInfo.GetDirectories())
}
Console.WriteLine(string.Format("============{0}==============", file.FullName));

举例使用
/// 递归获取文件夹目录下文件

Queue<string> _pathQueue = new Queue<string>();
_pathQueue.Enqueue(diChild.FullName);
while (_pathQueue.Count > 0)
throw new ArgumentNullException(pathName);

{
CSharpToolV2.LoopFolder(@"C:\Users\Administrator\Downloads\", (FileInfo file) =>
string _path = _pathQueue.Dequeue();
{
}

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/c/5639.shtml

相关文章

风云图片

推荐阅读

返回C#频道首页