Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检索单个目录中各个子文件夹中存在的所有扩展名为 .xml 的文件的文件名,
使用os.walk和str.endswith。
os.walk
str.endswith
代码:
import os xmlFiles = [] for directoryPath in os.walk(filePath): fileName = directoryPath[2] if fileName[:3] = 'xml':# or fileName.endswith('xml'): xmlFiles.append(fileName)