Pythonで全てのファイル名をリストアップする方法は何ですか?
全てのファイル名をリストするためには、osモジュールのlistdir()関数を使用することができます。以下はサンプルコードです:
import os
# 指定目录路径
path = "/path/to/directory"
# 使用listdir()函数列出目录中的所有文件名
files = os.listdir(path)
# 打印文件名
for file in files:
print(file)
“/path/to/directory”を実際にファイル名をリストアップしたいディレクトリのパスに置き換えてください。