在C#中循环浏览文件文件夹的最简单方法是什么? [英] What is the easiest way to loop through a folder of files in C#?
问题描述
我试图编写一个程序,该程序使用包含相关文件路径的配置文件来导航本地文件系统.我的问题是:在C#中执行文件I/O(从桌面应用程序到服务器再到服务器)执行文件I/O和文件系统导航时,可以使用的最佳实践是什么?
I trying to write a program that navigates the local file system using a config file containing relevant filepaths. My question is this: What are the best practices to use when performing file I/O (this will be from the desktop app to a server and back) and file system navigation in C#?
我知道如何使用Google,并且找到了几种解决方案,但是我想知道各种功能中哪一个最健壮和灵活.同样,如果有人对C#文件I/O的异常处理有任何建议,那也将非常有帮助.
I know how to google, and I have found several solutions, but I would like to know which of the various functions is most robust and flexible. As well, if anyone has any tips regarding exception handling for C# file I/O that would also be very helpful.
推荐答案
您不需要单独的库,请使用System.IO
命名空间中的类,例如File
,FileInfo
,Directory
,
You don't need a separate library, use the classes in the System.IO
namespace like File
, FileInfo
, Directory
, DirectoryInfo
. A simple example:
var d = new DirectoryInfo(@"c:\");
foreach(FileInfo fi in d.GetFiles())
Console.WriteLine(fi.Name);
这篇关于在C#中循环浏览文件文件夹的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!