例如
可以用以下方法:其中参数path所传递的值是所要查看的
文件夹的绝对路径!首先要导入System.IOC#//获取某个文件夹的
大小publicstaticlonggetDirectorySize(stringpath){DirectoryInfodirInfo=newDirectoryInfo(path)longsumSize=0FileSystemInfofsInfoforeach(fsInfoindirInfo.GetFileSystemInfos()){if(fsInfo.Attributes.ToString().ToLower()==directory){sumSize+=getDirectorySize(fsInfo.FullName)}else{FileInfofiInfo=newFileInfo(fsInfo.FullName)sumSize+=fiInfo.Length}}returnsumSize}VB.NET'获取某个文件夹的大小FunctiongetDirectorySize(ByValpathAsString)AsLongDimdirInfoAsNewDirectoryInfo(path)DimsumSizeAsLong=0DimfsInfoAsFileSystemInfoForEachfsInfoIndirInfo.GetFileSystemInfos()If(fsInfo.Attributes.ToString.ToLower=directory)ThensumSize+=getDirectorySize(fsInfo.FullName)ElseDimfiInfoAsNewFileInfo(fsInfo.FullName)sumSize+=fiInfo.LengthEndIfNext可以的
protected string get (string fileaddress)
{
string filename = Server.MapPath(fileaddress.Replace("~", ""))
FileInfo file = new FileInfo(filename)
if (file.Exists)
{
return filename.Substring(filename.LastIndexOf(".")).ToLower() + " - " + ((file.Length) / (1024.00 * 1024.00)).ToString("0.00") + "M"
}
else
return "no file"
}
前面要引用:
using System.IO
评论列表(0条)