ディレクトリ内のすべてのファイルをリストしようとしてきましたが、そのサブディレクトリ、そのパス、およびPythonでのサイズです。どういうわけか、そのディレクトリ内のファイルのみが表示され、サブディレクトリ内のファイルは表示されません。
import os
from os.path import join, getsize,abspath, isfile
fo=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でファイルパスとサイズのデータ構造を作成する方法を誰でも提案できます。ありがとうございました :)