using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Security;
using System.IO;
using System.IO.Compression;
using System.Xml;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
namespace HH.WMS.Utils
{
public partial class ZFiles
{
#region 获取文件大小并以B,KB,GB,TB方式表示[+2 重载]
///
/// 获取文件大小并以B,KB,GB,TB方式表示
///
/// 文件(FileInfo类型)
///
public static string GetFileSize(FileInfo File)
{
string Result = "";
long FileSize = File.Length;
if (FileSize >= 1024 * 1024 * 1024)
{
if (FileSize / 1024 * 1024 * 1024 * 1024 >= 1024) Result = string.Format("{0:############0.00} TB", (double)FileSize / 1024 * 1024 * 1024 * 1024);
else Result = string.Format("{0:####0.00} GB", (double)FileSize / 1024 * 1024 * 1024);
}
else if (FileSize >= 1024 * 1024) Result = string.Format("{0:####0.00} MB", (double)FileSize / 1024 * 1024);
else if (FileSize >= 1024) Result = string.Format("{0:####0.00} KB", (double)FileSize / 1024);
else Result = string.Format("{0:####0.00} Bytes", FileSize);
return Result;
}
///
/// 获取文件大小并以B,KB,GB,TB方式表示
///
/// 文件的具体路径
///
public static string GetFileSize(string FilePath)
{
string Result = "";
FileInfo File = new FileInfo(FilePath);
long FileSize = File.Length;
if (FileSize >= 1024 * 1024 * 1024)
{
if (FileSize / 1024 * 1024 * 1024 * 1024 >= 1024) Result = string.Format("{0:########0.00} TB", (double)FileSize / 1024 * 1024 * 1024 * 1024);
else Result = string.Format("{0:####0.00} GB", (double)FileSize / 1024 * 1024 * 1024);
}
else if (FileSize >= 1024 * 1024) Result = string.Format("{0:####0.00} MB", (double)FileSize / 1024 * 1024);
else if (FileSize >= 1024) Result = string.Format("{0:####0.00} KB", (double)FileSize / 1024);
else Result = string.Format("{0:####0.00} Bytes", FileSize);
return Result;
}
#endregion
}
}