我是python的初学者,这是我的第一个应用程序。因此,基本上,应用程序获取一个文件夹,其中包含mp3文件,并读取艺术家姓名的元数据,然后通过将歌曲复制到新创建的以艺术家姓名命名的子文件夹中,对歌曲进行相应的排序。如果没有艺术家的名字,它会创建一个名为“unsorted”的文件夹,并将文件复制到其中。我已经能够创建新的文件夹了,但是复制文件的最后一步是给我一个PermissionError。下面是代码和我得到的错误。
import os
import eyed3
import shutil
# get the path to music directory
musicFolder = input('please enter the full path of your music folder : ')
correctedPath = musicFolder.replace('/', '//')
musicList = []
# list of audio file objects
for _files in os.listdir(correctedPath):
if _files.endswith('.mp3'):
musicList.append(eyed3.load(correctedPath + '//' + _files))
sortedFolder = ''
# check tag info for album artist, and sort to folders
for _audioFiles in musicList:
if _audioFiles.tag.album_artist != None:
sortedFolder = correctedPath + '//' + _audioFiles.tag.album_artist
else:
sortedFolder = correctedPath + '//' + 'Unsorted'
if not os.path.exists(sortedFolder):
os.mkdir(sortedFolder)
shutil.copyfile(_audioFiles.path, sortedFolder)Error PermissionError: Errno 13权限被拒绝:'C://Users//Manu//Music//Music Test//Coldplay‘
任何帮助都是非常感谢的。耽误您时间,实在对不起。
发布于 2019-01-25 06:48:34
在我看来,你使用的是正斜杠/而你应该使用的是反斜杠。
'C://Users//Manu//Music//Music Test//Coldplay'应该是
'C:\\Users\\Manu\\Music\\Music Test\\Coldplay'更棒的是,Python内置了一些辅助路径的库: os.path和pathlib。
发布于 2019-01-25 16:13:47
shutil.copy2(src,dst)为我修复了这个问题。我把它从shutil.copyfile改过来了。
https://stackoverflow.com/questions/54356385
复制相似问题