我正在使用Python编写的程序,该程序将文件夹中的所有mp3文件复制到另一个目标位置,但是我遇到了问题。
这是代码:
import os
import shutil
def copy_music():
file_list = os.listdir(r"C:\Users\hp\Downloads")
saved_path = os.getcwd()
print("current working directory is "+saved_path)
os.chdir(r"C:\Users\hp\Downloads")
for file_name in file_list:
test = file_name.endswith('.mp3')
if test == True:
shutil.copy(file_name, 'c:\Users\hp\music')
os.chdir(saved_path)
print('all the mp3 files are successfully copied to your destination')
copy_music()
这是错误消息:
Traceback (most recent call last):
File "C:/Users/hp/Desktop/projects/code/copymusic.py", line 14, in <module>
copy_music()
File "C:/Users/hp/Desktop/projects/code/copymusic.py", line 11, in copy_music
shutil.copy(file_name, 'c:\Users\hp\music')
File "C:\Python27\lib\shutil.py", line 133, in copy
copyfile(src, dst)
File "C:\Python27\lib\shutil.py", line 96, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 22] invalid mode ('rb') or filename: 'Arcangel ?Bad Bunny - Original [Official Video].mp3'