【问题标题】:How to move and enter folders and subfolders in python [duplicate]如何在python中移动和输入文件夹和子文件夹[重复]
【发布时间】:2020-11-21 11:10:08
【问题描述】:

我有一个数据集和一个文件夹,在这个文件夹中我有几个子文件夹,其中有音频文件我需要在整个子文件夹上移动并获取文件和路径,我使用 python 有人有想法吗?

文件夹: 数据集 -> 文件夹:摇滚、雷格、嘻哈、经典、迪斯科、爵士、流行、布鲁斯、乡村、金属 -> 文件: “名称”.wav 我需要输入每个文件夹并获取文件和路径。 我的文件夹中有 100 个文件。

我什么都不尝试,因为我不知道该怎么做

【问题讨论】:

    标签: python file


    【解决方案1】:

    你应该使用os.walk

    import os
    
    for subdir, dirs, files in os.walk(rootdir):
        for file in files:
            filepath = subdir + os.sep + file    
            if filepath.endswith(".wav"):
                print(filepath)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2022-01-06
      • 2021-09-26
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 2011-11-17
      相关资源
      最近更新 更多