获得并处理一个文件夹下的所有文件
来源:互联网 发布:快消品数据汇报 编辑:程序博客网 时间:2024/05/19 19:15
.netFrameWork给我们提供了很多良好的文件操作类。
其中有一个地址操作类叫做Directory,其是一个静态类,使用这个类,将节省实例化的时间。
要获得一个文件夹下的所有文件,大约有两种方式:
(1)直接调用Directory类的静态方法。 string[] Directory.GetFiles(三个参数);其中第三个参数确定是否包含子目录
GetFiles(string path, string searchPattern, SearchOption searchOption)#region GetFiles(string path, string searchPattern, SearchOption searchOption)
//
// Summary:
// Returns the names of files in the specified directory that match the specified
// search pattern, using a value to determine whether to search subdirectories.
//
// Parameters:
// searchOption:
// One of the System.IO.SearchOption values that specifies whether the search
// operation should include all subdirectories or only the current directory.
//
// path:
// The directory to search.
//
// searchPattern:
// The search string to match against the names of files in path. The parameter
// cannot end in two periods ("..") or contain two periods ("..") followed by
// System.IO.Path.DirectorySeparatorChar or System.IO.Path.AltDirectorySeparatorChar,
// nor can it contain any of the characters in System.IO.Path.InvalidPathChars.
//
// Returns:
// A String array containing the names of files in the specified directory that
// match the specified search pattern. File names include the full path.
//
// Exceptions:
// System.UnauthorizedAccessException:
// The caller does not have the required permission.
//
// System.ArgumentNullException:
// path or searchpattern is null.
//
// System.IO.IOException:
// path is a file name.
//
// System.ArgumentException:
// path is a zero-length string, contains only white space, or contains one
// or more invalid characters as defined by System.IO.Path.InvalidPathChars.
// -or- searchPattern does not contain a valid pattern.
//
// System.IO.PathTooLongException:
// The specified path, file name, or both exceed the system-defined maximum
// length. For example, on Windows-based platforms, paths must be less than
// 248 characters and file names must be less than 260 characters.
//
// System.IO.DirectoryNotFoundException:
// The specified path is invalid (for example, it is on an unmapped drive).
public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption);
#endregion
//
// Summary:
// Returns the names of files in the specified directory that match the specified
// search pattern, using a value to determine whether to search subdirectories.
//
// Parameters:
// searchOption:
// One of the System.IO.SearchOption values that specifies whether the search
// operation should include all subdirectories or only the current directory.
//
// path:
// The directory to search.
//
// searchPattern:
// The search string to match against the names of files in path. The parameter
// cannot end in two periods ("..") or contain two periods ("..") followed by
// System.IO.Path.DirectorySeparatorChar or System.IO.Path.AltDirectorySeparatorChar,
// nor can it contain any of the characters in System.IO.Path.InvalidPathChars.
//
// Returns:
// A String array containing the names of files in the specified directory that
// match the specified search pattern. File names include the full path.
//
// Exceptions:
// System.UnauthorizedAccessException:
// The caller does not have the required permission.
//
// System.ArgumentNullException:
// path or searchpattern is null.
//
// System.IO.IOException:
// path is a file name.
//
// System.ArgumentException:
// path is a zero-length string, contains only white space, or contains one
// or more invalid characters as defined by System.IO.Path.InvalidPathChars.
// -or- searchPattern does not contain a valid pattern.
//
// System.IO.PathTooLongException:
// The specified path, file name, or both exceed the system-defined maximum
// length. For example, on Windows-based platforms, paths must be less than
// 248 characters and file names must be less than 260 characters.
//
// System.IO.DirectoryNotFoundException:
// The specified path is invalid (for example, it is on an unmapped drive).
public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption);
#endregion
(2)使用递归程序:找到其中的所有的子文件夹,子文件夹再调用函数本身获得其中的文件名。
使用两个函数string[] Directory.GetFiles()//三个参数,这里空着第三个参数,
和获得 子目录的函数 public static string[] GetDirectories(string path);
- 获得并处理一个文件夹下的所有文件
- linux c 读取并处理文件夹下的所有文件
- 获得文件夹下所有的txt文件
- 根据文件路径获得其所在文件夹,并删除该文件夹下后缀名为.tmp的所有文件
- 遍历一个文件夹下的所有文件及文件夹,并进行拷贝(代码)
- 删除一个文件夹下的所有文件
- 取出一个文件夹下的所有文件
- 获取一个文件夹下的所有文件
- 读取一个文件夹下的所有文件
- 读取一个文件夹下的所有文件
- 找出一个文件夹下的所有文件
- 更新一个文件夹下所有的文件
- 读取一个文件夹下所有的txt文件,并保存到一个txt文本中
- 批处理获得某个文件夹下的所有文件的文件名
- C++获得文件夹下所有文件的路径及文件名
- 程序片段----批处理获得文件夹下所有文件的名称
- STL---获取某个文件夹下的所有txt文件,并进行处理
- 批处理,用一个exe处理一个文件夹下的所有txt文件
- 使用 typedef 抑制劣质代码
- C++中指针和引用的区别
- 如何更改文件夹的图标!如何更改文件的图标!
- Swt/Swing Designer 破解 相关下载
- MySQL命令学习中....
- 获得并处理一个文件夹下的所有文件
- iframe 简介
- 开始Python -- 控制语句(2)
- 用PHP操纵Oracle的LOB类型的数据
- 简单的加密与解密示例
- 空中网创始人杨宁:忽悠就是融资能力
- 光盘上的OS - 自己动手制作Knoppix中文版
- Java与XML联合编程之SAX篇
- 忘掉web2.0,抓住web3.0