How can I list all the file names in Python?
To list all file names, you can use the listdir() function in the os module. Here is an example code:
import os
# 指定目录路径
path = "/path/to/directory"
# 使用listdir()函数列出目录中的所有文件名
files = os.listdir(path)
# 打印文件名
for file in files:
print(file)
Please replace /path/to/directory with the actual path of the directory you want to list the file names from.