python - 在 Python 中查找丢失的封面艺术

标签 python recursion

所以我想做的是遍历目录,对于包含 flac 文件的每个文件夹,检查它是否也包含“folder.jpg”文件。如果没有,则将目录打印到终端。告诉我哪里出错了。

noart = []
def noart():
#pwd is defined
  for root, dirnames, filenames in os.walk(pwd):
    for filename in fnmatch.filter(filenames, "*.flac"):
      if "folder.jpg" not in os.getcwd():
        noart.append(os.path.join(root, filename))

最佳答案

您需要在 os.getcwd() 上调用 os.listdir:

noart = []
def noart():
#pwd is defined
  for root, dirnames, filenames in os.walk(pwd):
    for filename in fnmatch.filter(filenames, "*.flac"):
      if "folder.jpg" not in os.listdir(os.getcwd()):
        noart.append(os.path.join(root, filename))

os.getcwd() 只返回当前工作目录的路径:

>>> os.getcwd()
'/Users/aj'
>>> os.listdir(os.getcwd())
['Desktop', 'Documents', ...]

关于python - 在 Python 中查找丢失的封面艺术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29616941/

相关文章:

python - 找不到 pyinstaller 添加数据文件

python - 类模板的习惯用法或设计模式?

python - python中的排序错误

java - 使用递归方法进行三元搜索

C++多维结构数组

java - 我的快速排序实现使用了太多比较,但无法确定原因

Python套接字未从C++ Boost asio接收所有数据

python - 禁用 Nose 的一个示例测试

python - 无法删除.text。使用正则表达式

javascript - AngularJS 中的递归菜单