import sys,os

def get(path):
allfile
= {}
for root,dirs,files in os.walk(path):
for onefile in files:
fname
= os.path.join(root,onefile)
fsize
= os.stat(fname).st_size
if allfile.has_key(fsize):
allfile[fsize].append(fname)
else:
allfile[fsize]
= [fname]
fsize_key
= allfile.keys()
fsize_key.sort()
result
= []
for x in fsize_key:
for y in allfile[x]:
t
= (x,y)
result.append(t)
for x in range(1,4):
print result[-x]
#return result[-3:]

if __name__ == '__main__':
## if len(sys.argv)==1:
#
# print 'no good path'
#
# else:
#
# path = os.path.abspath(sys.argv[1])
#
# if not os.path.isdir(path):
#
# print "%s is not exist" % path
#
# else:
#
# top = get(path)
#
# for (s,f) in top:
#
# print '%s ---> %s' % (f,s)
top = get(r'C:\Users\eth1\Desktop\temp')
#for k in top:
#prinit "%s -- %s" % (k[1],k[0])
os.listdir(path) --> 
os.stat(file).st_size --> size
os.walk(path) --> 
sys.argv[0] --> file address

  

 posted on 2011-07-19 16:00  eth0  阅读(286)  评论(0编辑  收藏  举报