我正在嘗試獲取文件名中包含特定字符串的文件。例如目錄中有幾個文件,我想要文件名中具有“索引”或“導(dǎo)出”的文件。任何一段代碼或方法都會有所幫助
1 回答
德瑪西亞99
TA貢獻(xiàn)1770條經(jīng)驗 獲得超3個贊
您可以使用os module. 在里面os.walk,您可以使用所需的路徑,我正在使用當(dāng)前目錄。
import os
for path, b, files in os.walk(os.getcwd()):
print('The path is ', path)
for file in files:
if 'index' in file or 'export' in file:
print(file)
添加回答
舉報
0/150
提交
取消
