文件在文件夹和子文件夹中计数 [英] Files count in folder and sub folders
问题描述
Hello Friends,
我在主文件夹中有很多子文件夹
示例:
First Main文件夹名称:317_ABC。
第二个主文件夹名称:BMTFT(在这个主文件夹中我有很多子文件夹)
30-4 no.5(文件内)
30-4 no.6(文件内)
30-4 no.8(文件内)
37779432(文件内)
207758581(文件内)
254128794(文件内)
如何使用文件名和路径名来计算文件数(即317_ABC \BMTFT \ 30-4 no.5 \< files name = >?
希望这是明确的。请任何人指导我吗?
Hello Friends,
I have lot of sub-folders in main folder
Example :
First Main folder name : 317_ABC.
Second main folder name: BMTFT (in this main folder i have lot of sub folders)
30-4 no.5 (inside the files)
30-4 no.6 (inside the files)
30-4 no.8 (inside the files)
37779432 (inside the files)
207758581 (inside the files)
254128794 (inside the files)
How to get the files count with file name and path name (i.e., 317_ABC\BMTFT\30-4 no.5\<files name="">?
Hope this is clear. please any one guide me?
推荐答案
你必须正在搜索 Directory.GetFiles(path,searchPattern,SearchOption) [ ^ ] Directory.GetFiles()的重载。
试试这种方式:
You must be searching for Directory.GetFiles(path, searchPattern, SearchOption)[^] overload of Directory.GetFiles().
Try this way:
string[] files = directory.GetFiles(@"c:\windows\system32", "*.dll", SearchOption.AllDirectories);
return files.Length;
这里路径
指定路径, searchPattern
指定您的通配符(例如,*,*。format)和 SearchOption
提供包含子目录的选项。
此搜索的返回数组的Length属性将为您的特定搜索模式和选项提供正确的文件计数。
同样检查类似的答案这里 [<一个HREF =http://stackoverflow.com/questions/2106877/is-there-a-faster-way-than-this-to-find-all-the-files-in-a-directory-and-all-sub / 2107294#2107294target =_ blanktitle =New Window> ^ ]
Here Path
specifies the path, searchPattern
specifies your wildcards (e.g., *, *.format) and SearchOption
provides the option to include subdirectories.
The Length property of the return array of this search will provide the proper file count for your particular search pattern and option.
Also check similar answer here[^]
尝试:
Try:
string[] files = Directory.GetFiles(@"D:\Temp\", "*.*", SearchOption.AllDirectories);
Console.WriteLine(files.Length);
这将为您提供所有文件:检查您必须单独打开它们的内容。 />
以上代码是VB.net?
不,但差异微不足道。尝试:
This will give you all the files: to check contents you would have to open them all individually.
"the above code is VB.net?"
No, but the differences are trivial. Try:
Dim files As String() = Directory.GetFiles("D:\Temp\", "*.*", SearchOption.AllDirectories)
Console.WriteLine(files.Length)
我建议你从这里开始:如何:枚举目录和文件 [ ^ ]
演练:在Visual Basic .NET中操作文件和文件夹 [ ^ ]
Directory.GetFiles Method(String) [ ^ ]
I would suggest you to start here: How to: Enumerate Directories and Files[^]
Walkthrough: Manipulating Files and Folders in Visual Basic .NET[^]
Directory.GetFiles Method (String)[^]
这篇关于文件在文件夹和子文件夹中计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!