可以使用Python语言中的os模块获取文件,并使用os.walk()函数遍历目录树。在遍历时,可以使用一个判断来忽略隐藏文件夹。
代码示例:
import os
def get_files(path): for root, dirs, files in os.walk(path): #过滤隐藏文件夹 dirs[:] = [d for d in dirs if not d.startswith('.')] for file in files: yield os.path.join(root, file)
for file in get_files('/path/to/leaf/folder'): print(file)
上一篇:编写一个文本冒险游戏