所以我想做的是遍历目录,对于包含 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/