c# 获取文件夹大小
private long GetDirectorySizeMethod1(string directory)
{
long directorySize = 0;
DirectoryInfo di = new DirectoryInfo(directory);
if (!di.Exists)
{
Console.WriteLine("Directory {0} is not exist!", directory);
return 0;
}
foreach (FileInfo fi in di.GetFiles())
{
directorySize += fi.Length;
}
DirectoryInfo[] dirs = di.GetDirectories();
foreach (DirectoryInfo sondir in dirs)
{
directorySize += GetDirectorySizeMethod1(sondir.FullName);
}
return directorySize;
}
private long GetDirectorySizeMethod2(string directory)
{
long directorySize = 0;
if (File.Exists(directory))
{
FileInfo fi = new FileInfo(directory);
return fi.Length;
}
else
{
string[] strs = Directory.GetFileSystemEntries(directory);
foreach (string str in strs)
{
directorySize += GetDirectorySizeMethod2(str);
}
}
return directorySize;
}
c# 获取文件夹大小的更多相关文章
- Linux C++获取文件夹大小
项目中要计算指定文件夹的大小.百度查到这篇文章,https://my.oschina.net/Tsybius2014/blog/330628方法可行,运行正确. 拿到我们的项目中,却遇到一些问题:程序 ...
- 用C#实现获取文件夹大小的源代码
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- 【VBS】获取文件夹大小
文件截图: 运行结果: 第一步:编写脚本 GetFloderSize.vbs 1 '获得文件夹的大小 by 王牌飞行员(https://www.cnblogs.com/KMould/p/1233481 ...
- python 获取文件夹大小
__author__ = 'bruce' import os from os.path import join,getsize def getdirsize(dir): size=0l for (ro ...
- C#获取文件和文件夹大小
代码如下: /// <summary> /// 获取文件夹大小 /// </summary> /// <param name="dirPath"> ...
- python3获取文件及文件夹大小
获取文件大小 os.path.getsize(file_path):file_path为文件路径 >>> import os >>> os.path.getsize ...
- python 获取文件和文件夹大小
1.os.path.getsize可以获取文件大小 >>> import os >>> file_name = 'E:\chengd\Cd.db' >> ...
- python获取文件及文件夹大小
Python3.3下测试通过 获取文件大小 使用os.path.getsize函数,参数是文件的路径 获取文件夹大小 import os from os.path import join, getsi ...
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
android 获取文件夹.文件的大小 以B.KB.MB.GB 为单位 public class FileSizeUtil { public static final int SIZETYPE_B ...
随机推荐
- 为什么 SQLite 用 C 编写?
简评:SQLite 官方出品. C是最好的选择 从 2000 年 5 月 29 日开始,SQLite 就选择了 C 语言.直到今天,C 也是实现 SQLite 这样软件库的最佳语言. C语言是实现 S ...
- python3入门之集合set
之前介绍python的数据结构时,没有介绍set(集合)现在在这里稍微介绍下: set原理 Python 还 包 含 了 一 个 数 据 类 型-- set ( 集 合 ) . 集 合 是 一 个 无 ...
- 51nod1238. 最小公倍数之和 V3(数论)
题目链接 https://www.51nod.com/Challenge/Problem.html#!#problemId=1238 题解 本来想做个杜教筛板子题结果用另一种方法过了...... 所谓 ...
- es6 简单封装一个 省市县三级下拉框
废话不多说,直接上效果图和代码: 1,index.js function $(el){ return document.getElementById(el) } let render = Symbol ...
- springboot(九)-log配置
spring项目放到tomcat中运行,我们可以在tomcat的logs文件夹下面生成log文件.那么我们的springboot项目没有放到系统安装的tomcat容器中,怎么设置生成log文件呢? 有 ...
- python 元类以及练习
''' # 知识储备exec() # 参数1:字符串形式的命令 # 参数2:全局作用域(字典形式),如果不指定默认就使用globals() # 参数3:局部作用域(字典形式),如果不指定默认就使用lo ...
- Python数据类型(数字)
文章内容参考了教程:http://www.runoob.com/python/python-basic-syntax.html#commentform Python 变量类型 变量存储在内存中的值.这 ...
- selenium+junit4实现参数化自动化测试
业务场景:在www.1905.com电影网中实现两个用户的登陆操作. 代码如下: package com.m1905.junit; import java.util.Arrays; import ja ...
- 【ExtJS】FormPanel 布局(二)
周末2天好好学习了下布局,现在都给实现了吧. 5.border布局: Border布局将容器分为五个区域:north.south.east.west和center.除了center区域外,其他区域都需 ...
- 批量修改dos文件到unix
1. 安装dos2unix 2. 执行:find ./ -type f | xargs dos2unix