计算某一路径下的所有目录或是文件数量
2023-09-27 14:21:30 时间
计算某一路径下的所有目录或是文件数量,可以参考下面代码示例:
不管是计算目录或理文件,2个方法均带2个参数,前者是传入的是物理路径,第二个传的是布尔值的参数,即是说可以计算是否包含子目录。
目录:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public static int DirectoryCount(string physicalPath, bool isIncludeSubDirectory) { int count = 0; if (isIncludeSubDirectory) count = Directory.GetDirectories(physicalPath, "*", SearchOption.AllDirectories).Length; else count = Directory.GetDirectories(physicalPath, "*", SearchOption.TopDirectoryOnly).Length; return count; }
文件:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public static int FileCount(string physicalPath, bool isIncludeSubDirectory) { int count = 0; if (isIncludeSubDirectory) count = Directory.GetFiles(physicalPath, "*.*", SearchOption.AllDirectories).Length; else count = Directory.GetFiles(physicalPath, "*.*", SearchOption.TopDirectoryOnly).Length; return count; }
相关文章
- python读取mongodb并写入文件
- TPshop商城 Getshell后门文件分析与复现
- 计算目录下文件数
- 不用装工具,一条 Linux 命令就能实现文件上传下载!
- Java使用线程池递归压缩文件夹下面的所有子文件
- AjaxFileUpload文件上传组件(php+jQuery+ajax)
- java计算过G文件md5 值计算
- 【云计算】Docker容器不能修改hosts文件怎么解决?
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- Linux·Uboot-kernel-根文件·下载地址
- Java 使用MD5、SHA1、SHA-256和SHA-512计算文件和字符串哈希值(hash checksum)
- 通过avro合并大文件 并计算文件词频
- visual studio 2010 c++ fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或
- 如何在对话框中实现文件拖放功能
- dump命令1——ITL文件dump
- 用numpy计算成交量加权平均价格(VWAP),并实现读写文件
- 【Python 入门】文件IO
- iReport3.0+MyEclipse8.5生成PDF文件