#coding: Utf-8
Import OS;
def sortlist (item):
return item[1];
def readsize (fileName):
return float (os.path.getsize (fileName));
def writeall (path):
L = []
Loger = open ("Test.log", "w");
writer = open ("Path.txt", "w");
Reader = open ("Path.txt", "R");
size = 0;
For root,dirs,files in Os.walk (path):
For Filespath in Files:
Try
Fllepath = Os.path.join (Root,filespath);
FileSize = Float (readsize (fllepath)/1024);
Size + = FileSize;
x = (Fllepath,int (fileSize));
L.append (x);
Except
Loger.write ("read:" +os.path.join (Root,filespath) + "File size failed!");
Continue
L = sorted (l,key=sortlist,reverse=true);
For item in L:
strtmp = "";
If float (item[1]/1024) > 1024:
strtmp = item[0]+ "" "+str (int (float (item[1]/1024/1024)) +" gb\n ";
Elif Item[1] > 1024:
strtmp = item[0]+ "" "+str (int (float (item[1]/1024)) +" mb\n ";
Else
strtmp = item[0]+ "" +str (Item[1]) + "kb\n";
Writer.write (strtmp);
A = Round (float (size/1024/1024), 2) #四舍五入取小数点后两位
Writer.write ("Shared disk space:" +str (a) + "GB");
Print "Shared disk space:" +str (a) + "GB"
Loger.close ();
Writer.close ();
"Print (Reader.read ());
Reader.close ();
#当前目录
#fileName = OS.GETCWD ();
Print "D disk has used space:"
FileName = ' d:/';
Writeall (FileName);
Print "e-disk has used space:"
FileName = ' e:/';
Writeall (FileName);
Print "End Please verify"
#raw_input ("============end============");
Python Statistics disk usage