![見出し画像](https://assets.st-note.com/production/uploads/images/60751612/rectangle_large_type_2_f9ef5aca2705c1f110c3a662796e20d7.png?width=1200)
python ファイル一覧を取得してファイルサイズを表示する
コード
import os
path = r"C:\Users\Downloads"
files = os.listdir(path)
for file in files :
# フルパスにする
full_path = os.path.join(path, file)
# ファイルのサイズ取得と表示
print(file,os.path.getsize(full_path)/1000/1000,"MB")
path にファイル一覧を取得するディレクトリのパスを指定します
/1000/1000 でMBにしています。
おすすめ本
この記事が気に入ったらサポートをしてみませんか?