我一直在嘗試列出目錄及其子目錄中的所有文件,其路徑及其在python中的大小。不知何故,僅顯示其目錄中的文件,而不顯示子目錄中的文件。import osfrom os.path import join, getsize,abspath, isfilefo=open("Size Listing.txt","a")def size_list(mypath):f = []for (dirpath, dirname, filenames) in os.walk(mypath): f.extend(filenames)for i in f: fo.write("\nPath: ") fo.write(abspath(i)) fo.write(" Size: ") fo.write(str(getsize(join(mypath,i)))) fo.write(" bytes")fo.close()有人可以幫我嗎?也有人可以建議如何在Python中為文件路徑和大小創建數據結構,因為我還需要進行一些排序。謝謝 :)
添加回答
舉報
0/150
提交
取消