如何访问给定文件夹中的每个文件夹 [英] how to access each folder in a given folder
本文介绍了如何访问给定文件夹中的每个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们.我有一个文件夹,其中有4-5个文件夹.我想在每个文件夹中修改一个名为"kkj"的文件.我不知道如何处理主文件夹中的子文件夹.请帮我这样做.
非常感谢您
Hi Friends. I have a folder in which there are 4-5 folders. I want to modify a file of name "kkj" in each folder. I don''t know how to deal the sub folders in the main folder as an iteration. Please help me doing this.
Thank you so much
推荐答案
请使用此方法 System.IO.Directory.GetFiles(String,String,SearchOption) [ ^ ].
这使您可以递归搜索目录.适用于.NET 2.0、3.0、3.5、4.0.
干杯!
Please use this method System.IO.Directory.GetFiles(String, String, SearchOption)[^].
This will let you search a directory recursively. Works in .NET 2.0, 3.0, 3.5, 4.0.
Cheers!
此 [
This[^] little code snippet should surely help you.
此外,Manfred和Abhinav的答案:与微软如何对待口罩有关的一个难题是违反直觉的.请参阅以下讨论: Directory.Get.Files搜索模式问题 [ ^ ].
请注意以下代码示例中的Where
和ToLower
:
In addition the the Answers by Manfred and Abhinav: there is one difficulty related to how Microsoft treats the masks, it is counter-intuitive. Please see this discussion: Directory.Get.Files search pattern problem[^].
Pay attention toWhere
andToLower
in this code sample:
var files = Directory.GetFiles(
dir, "*.exe").
Where(item => item.ToLower().EndsWith(".exe"));
(如果参考问题"页面,请参阅说明.)
(See the explanation if the references Question page.)
这篇关于如何访问给定文件夹中的每个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文