【问题标题】:How Can I Find For Example *.mp3 Files From All Directories Of My System? [closed]如何从我的系统的所有目录中查找示例 *.mp3 文件? [关闭]
【发布时间】:2021-01-05 19:46:03
【问题描述】:

我想从我系统的每个目录中找到所有 .mp3 格式文件的绝对路径。

【问题讨论】:

  • 欢迎堆栈溢出。不幸的是,这不是代码编写或教程服务,我们要求问题包括minimal reproducible example,包括您根据自己的研究已经尝试过的内容以及您的结果出了什么问题
  • 您已包含 Python 标记。你想用 Python 做到这一点吗?如果是这样,上下文是什么?请阅读How to Ask
  • 你有没有尝试过?你到底卡在哪里了?

标签: python operating-system


【解决方案1】:

如果您使用的是 python,os.walk 可以帮助您。

这样的简单代码可以工作:

import os

for data in os.walk('d:\\music'): # where to start searching
    dir_path, folders, files = data

    for f in files:
        if f.lower().endswith('.mp3'):
            print(os.path.join(dir_path, f))

【讨论】:

    猜你喜欢
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2012-06-29
    • 2016-01-30
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多