Python。IOError:[Errno 13]权限被拒绝:当我复制fi时

2024-06-16 11:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个文件夹:输入,输出-它不是磁盘D上的系统文件夹:-Windows 7。Out contain“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'

怎么了?


Tags: in命令txt文件夹windows系统lineout
3条回答

阅读docs

shutil.copyfile(src, dst)

Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name; look at copy() for a copy that accepts a target directory path.

我解决了这个问题,你应该是目的地的完整目标文件名

目的地=路径目录+文件名。*

我在shuil中使用此代码fir copy wav文件:

    # open file with QFileDialog

    browse_file = QFileDialog.getOpenFileName(None, 'Open file', 'c:', "wav files (*.wav)")

    # get file name 

    base = os.path.basename(browse_file[0])
    os.path.splitext(base)
    print(os.path.splitext(base)[1])

    # make destination path with file name

    destination= "test/" + os.path.splitext(base)[0] + os.path.splitext(base)[1]
    shutil.copyfile(browse_file[0], destination)

使用 shutil.copy而不是shutil.copyfile

示例:

shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath)

相关问题 更多 >