我给出了一个函数的路径,我希望这个函数可以在这个路径中的每个文件夹中观看,如果文件夹中有一个文件夹:也观看。
def function(path):
for element in os.listdir(path):
element_path = os.path.abspath(element)
if os.isdir(element_path):
path = os.path.join(path, element)
function(path)
elif ... # elif elment is an img do something
此代码有效,但是当文件夹中有文件夹时它不起作用:/