诱变所有文件类型

时间:2013-10-03 18:04:42

标签: python mutagen

我被赋予了一项任务,即可以将读取所有MP3文件的函数更改为读取Mutagen能够读取的任何类型的文件。我想用手工做吗? (I.E如果.endswith = this或that),或者是否有通用的方法来实现这一目标?

循环的方式如下:

for root, dirs, files in os.walk("."):
    for filename in files:
        if filename.lower().endswith(".mp3"):
            fullname = os.path.join(root, filename)

1 个答案:

答案 0 :(得分:-1)

supported = ['.mp3','.ogg','.wma'] #put all known here

for root, dirs, files in os.walk("."):
    for filename in files:
        if filename.lower() in supported: #test if filename ext is in supported
            fullname = os.path.join(root, filename)