首页 > 其他 > 详细

获取文件大小

时间:2018-02-02 18:06:13      阅读:206      评论:0      收藏:0      [点我收藏+]

Js:

function getFileSize()
{
var size=0;
var files = document.getElementById("file").files;
for(var i=0; i< files.length; i++){
var fileSize=files[i].size;
//var count=Math.round(fileSize/1024.00);
//alert(s);
size+=fileSize;
}
alert(formatBytes(size));
}

function formatBytes(bytes) {
if(bytes < 1024) return bytes + " Bytes";
else if(bytes < 1048576) return(bytes / 1024).toFixed(2) + " KB";
else if(bytes < 1073741824) return(bytes / 1048576).toFixed(2) + " MB";
else return(bytes / 1073741824).toFixed(3) + " GB";
};

 

C#:

public static string GetFileSize(string sFullName)
{
long lSize = 0;
if (System.IO.File.Exists(sFullName))
lSize = new FileInfo(sFullName).Length;
return CountSize(lSize);
}

public static string CountSize(long Size)
{
string m_strSize = "";
long FactSize = 0;
FactSize = Size;
if (FactSize < 1024.00)
m_strSize = FactSize.ToString("F2") + " Byte";
else if (FactSize >= 1024.00 && FactSize < 1048576)
m_strSize = (FactSize / 1024.00).ToString("F2") + " K";
else if (FactSize >= 1048576 && FactSize < 1073741824)
m_strSize = (FactSize / 1024.00 / 1024.00).ToString("F2") + " M";
else if (FactSize >= 1073741824)
m_strSize = (FactSize / 1024.00 / 1024.00 / 1024.00).ToString("F2") + " G";
return m_strSize;
}

获取文件大小

原文:https://www.cnblogs.com/Tang-X/p/8406169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!