`shutil.copyfile` Error: Permissions Denied

时间秒杀一切 提交于 2020-01-06 06:10:44

问题


I have worked through a number of other threads on this, but not of their solutions seem to work here, that or I am not understanding properly, and would love your help.

I am getting a:

IOError: [Errno 13] Permission denied: 'W:\\test\\Temporary Folder 195\\Sub-fold1 

This is the general code i started with.

    summary_file = r'W:/test/SDC Analysis Summary.docm'
    shutil.copyfile(summary_file, os.getcwd())

I have also varied this a little bit based on other threads, specifically replacing summary_file with the actual text and also adding \ to the end of working directory without success. Really don't know what I'm missing here. I know that the Documentation is looking for complete paths, but I believe I am satisfying that requirement. What am I missing here?

Note: there is a desire to use copyfile over copy due to the speed increase.


回答1:


From the documentation:

 dst must be the complete target file name

You can't just use os.getcwd() as the destination.




回答2:


you should be the complete target file name for destination

destination = pathdirectory + filename.*

I use this code fir copy wav file with shutil :

    # 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)


来源:https://stackoverflow.com/questions/45149614/shutil-copyfile-error-permissions-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!