在不知道扩展名的情况下在文件夹中查找文件?

Kaz*_*ama 3 python directory search file match

假设我想在名为“myfolder”的文件夹中搜索文件名“myfile”,在不知道文件格式的情况下怎么做?另一个问题:如何列出一个文件夹中的所有文件它的子文件夹中的所有文件(等)?谢谢你。

Sam*_*zzo 5

import os
import glob
 
path = 'myfolder/'
for infile in glob.glob( os.path.join(path, 'myfile.*') ):
    print "current file is: " + infile
Run Code Online (Sandbox Code Playgroud)

如果要列出文件夹中的所有文件,只需将 for 循环更改为

for infile in glob.glob( os.path.join(path) ):
Run Code Online (Sandbox Code Playgroud)