zoukankan      html  css  js  c++  java
  • 获取文件大小

    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;
    }

  • 相关阅读:
    简明Secure boot介绍
    密码学有什么用?
    mkimage, no such file or dir
    嵌入式系统安全简介
    希尔排序
    jQuery选择器
    css 选择器
    安装 SQL Server 2008 和管理工具 SQL Server 2008 management studio 及相关问题解决
    mac下安装安卓开发环境
    IOS开发小记-内存管理
  • 原文地址:https://www.cnblogs.com/Tang-X/p/8406169.html
Copyright © 2011-2022 走看看