Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python recursively find files with specific ext

def walk_ext_file(dir_path, ext_list):
   # @dir_path参数:遍历的目录
   # @ext_list参数:拓展名列表,例['.mp4', '.mkv', '.flv']
    # 遍历
    for root, dirs, files in os.walk(dir_path):
        # 获取文件名称及路径
        for file in files:
            file_path = os.path.join(root, file)
            file_item = os.path.splitext(file_path)
            # 输出指定扩展名的文件路径
            if file_item[1] in ext_list:
                print(file_path)http://www.showmeai.tech/article-detail/python-os-file-dir-methods#%E9%81%8D%E5%8E%86%E6%93%8D%E4%BD%9C
Source by www.adamsmith.haus #
 
PREVIOUS NEXT
Tagged: #Python #recursively #find #files #specific #ext
ADD COMMENT
Topic
Name
4+6 =