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

  • 相关阅读:
    无线桥接(WDS)如何设置?
    Linux内核的整体架构简介
    Efuse--芯片存储
    Linux下编写和加载 .ko 文件(驱动模块文件)
    统计难题
    最少拦截系统
    (比赛)B
    (比赛)A
    F
    K
  • 原文地址:https://www.cnblogs.com/Tang-X/p/8406169.html
Copyright © 2011-2022 走看看