关于Windows Shell编程
请问如何获得文件的大小,请前辈指点,非常感谢
[解决办法]
//file是路径
string lenghtsize = file.Length.ToString();//大小
Int64 fileSize = Convert.ToInt64(lenghtsize);
MyMetadata.FileSize.DisplayValue = FormatFileSize(fileSize);//格式化大小
#region 格式化图片大小
public static String FormatFileSize(Int64 fileSize)
{
if (fileSize < 0)
{
throw new ArgumentOutOfRangeException("fileSize");
}
else if (fileSize >= 1024 * 1024 * 1024)
{
return string.Format("{0:########0.00} GB", ((Double)fileSize) / (1024 * 1024 * 1024));
}
else if (fileSize >= 1024 * 1024)
{
return string.Format("{0:####0.00} MB", ((Double)fileSize) / (1024 * 1024));
}
else if (fileSize >= 1024)
{
return string.Format("{0:####0.00} KB", ((Double)fileSize) / 1024);
}
else
{
return string.Format("{0} bytes", fileSize);
}
}
#endregion
------解决方案--------------------
+1