代码如下:
import os dirpath = 'D:\\' t = [] for root,dirs,files in os.walk(dirpath): for file in files: temp = os.path.join(root,file).replace('\\','\\\\') if os.path.isfile(temp): t.append(temp) if (os.path.exists("filesize.txt")): os.remove("filesize.txt")
f=open("filesize.txt","a",encoding='utf-8') i = 0 while i < len(t): f.writelines('size:'+ str(os.path.getsize(t[i])) + "\n" + t[i]+ "\n") i = i +1 f.close()
标签:文件大小,temp,文件,获取,filesize,path,txt,os From: https://www.cnblogs.com/hydd/p/16636044.html