gpt4 book ai didi

c# - 文件夹中的文件数

转载 作者:IT王子 更新时间:2023-10-29 03:42:17 30 4
gpt4 key购买 nike

如何使用 ASP.NET 和 C# 从文件夹中获取文件数?

最佳答案

您可以使用 Directory.GetFiles 方法

另见 Directory.GetFiles Method (String, String, SearchOption)

您可以在此重载中指定搜索选项。

TopDirectoryOnly:仅在搜索中包含当前目录。

AllDirectories:包括当前目录和搜索操作中的所有子目录。此选项包括重新分析点,例如已安装的驱动器和搜索中的符号链接(symbolic link)。

// searches the current directory and sub directory
int fCount = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Length;
// searches the current directory
int fCount = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).Length;

关于c# - 文件夹中的文件数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2242564/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com