import os def get_size(start_path = '.'): total_size = 0 for dirpath, dirnames, filenames in os.walk(start_path): for f in filenames: fp = os.path.join(dirpath, f) # skip if it is symbolic link if not os.path.islink(fp): total_size += os.path.getsize(fp) return total_size def wjsl(aae): ls=os.listdir(aae) return len(ls) dizhi="d:\\python37\\abc\\" size=get_size(dizhi) sum=wjsl(dizhi) print('%.3f' %(size/1024/1024),'M') print(str(sum),"个文件")
标签:fp,python,dizhi,指定,文件夹,path,total,os,size From: https://www.cnblogs.com/xkdn/p/17048448.html