C# 对目录进行爬网
我有以下测试路径:C# 对目录进行爬网,c#,C#,我有以下测试路径: private static string dCrawler = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "TestLetters"; 有没有办法说: foreach (item in dCrawler) { if (item.isFile) { // check file info date modified code } else
private static string dCrawler = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "TestLetters";
有没有办法说:
foreach (item in dCrawler)
{
if (item.isFile)
{
// check file info date modified code
} else
{
foreach (fileinfo file in ...
}
}
到目前为止,我只找到了检查目录中文件的方法。唯一的方法是使用两个单独的循环,一个用于文件,另一个用于文件夹?您可以使用
Directory.GetFiles()
返回一个字符串[]
,并使用该字符串值创建文件信息
。像这样
foreach (string n in Directory.GetFiles(dCrawler))
{
FileInfo b = new FileInfo(n);
}
要获取目录,您可以类似地使用Directory.GetDirectories()代码>
您可以使用Directory.GetFiles()
返回一个字符串[]
,并使用该字符串值创建文件信息
。像这样
foreach (string n in Directory.GetFiles(dCrawler))
{
FileInfo b = new FileInfo(n);
}
要获取目录,您可以类似地使用Directory.GetDirectories()代码>
在MSDN上签出在MSDN上签出这只适用于我假设的文件?我必须为DirectoryInfo创建一个类似的foreach?谢谢,这让我有了一个良好的基础,可以用它做我需要做的一切。:)这只适用于我假设的文件?我必须为DirectoryInfo创建一个类似的foreach?谢谢,这让我有了一个良好的基础,可以用它做我需要做的一切。:)