G-7*_*-71 26 python windows windows-7
我有两个文件夹:In,Out - 它不是磁盘D上的系统文件夹: - Windows 7. Out包含"myfile.txt"我在python中运行以下命令:
>>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" )
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" )
File "C:\Python27\lib\shutil.py", line 82, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: 'D:\\In'
Run Code Online (Sandbox Code Playgroud)
有什么问题?
小智 13
使用shutil.copy而不是shutil.copyfile
例:
shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath)
Run Code Online (Sandbox Code Playgroud)
使用shutil.copy2代替shutil.copyfile
import shutil
shutil.copy2('/src/dir/file.ext','/dst/dir/newname.ext') # file copy to another file
shutil.copy2('/src/file.ext', '/dst/dir') # file copy to diff directory
Run Code Online (Sandbox Code Playgroud)