码迷,mamicode.com
首页 > Windows程序 > 详细

C# 文件大小

时间:2015-10-19 23:59:54      阅读:390      评论:0      收藏:0      [点我收藏+]

标签:

  

/// <summary>
/// 获取文件大小
/// </summary>
/// <param name="sFullName"></param>
/// <returns></returns>
public static long TGetFileSize(string sFullName)
{
long lSize = 0;
if (File.Exists(sFullName))
lSize = new FileInfo(sFullName).Length;
return lSize;
}

public string GetFileSize(string sFileFullName)
{
FileInfo fiInput = new FileInfo(sFileFullName);
double len = fiInput.Length;

string[] sizes = { "B", "KB", "MB", "GB" };
int order = 0;
while (len >= 1024 && order + 1 < sizes.Length)
{
order++;
len = len / 1024;
}

string filesize = String.Format("{0:0.##} {1}", len, sizes[order]);
return filesize;
}

public static bool FileIsLargerThan1KB(string sFileFullName)
{
FileInfo fiInput = new FileInfo(sFileFullName);
double len = fiInput.Length;

len = len / 1024 / 1024;
return len > 1;
}

C# 文件大小

标签:

原文地址:http://www.cnblogs.com/ArRan/p/4893298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!