Pythonshutil.复制[错误13]权限被拒绝

2024-10-01 04:53:03 发布

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

这是代码中出现问题的部分。我缺少一些权限吗?在

def addcontent(job,jobpath): 
    contentpath=''
    if job == "FULL":
        print('This job will copy data from '+full_contentpath)
        contentpath=str(full_contentpath)
    elif job == "INCR":
        print('This job will copy data from '+incr_contentpath)
        contentpath=str(incr_contentpath)
    elif job == "DIFF":
        print('This job will copy data from '+diff_contentpath)
        contentpath=str(diff_contentpath)
    else:
        pass
    os.makedirs(jobpath)
    for file in glob.iglob(contentpath+r'\*'):
        shutil.copy(file,jobpath)

''' Method versionfile() will be called only for bkp_witout_inp() methods 
'''        
def versionfile():
        global mainpath
        #we will also create a file for checking versioning - Every job will contain a new version of this file. Prior to running this job we shall touch it to get a new version
        if os.access(mainpath+r"\versionfile.txt",os.F_OK):
            os.system(r"copy /b "+"\""+mainpath+r"\versionfile.txt"+"\""+r" +,,")
        else:
            os.system(r"fsutil file createnew "+mainpath+r"\versionfile.txt 10240000")
        # the above if..else clause will modfiy the file if it exists

这是我得到的错误。我可以向你保证,我没有试图复制回收站,但它仍然失败

^{pr2}$

第一次调用此方法时,路径已成功创建,但下一次我遇到此错误。你知道为什么第二次路径存在时它失败了吗?在

更新

终于发现了我的愚蠢错误。为job发送的值是FULL,INCREMENTAL&DIFFERENTIAL而不是INCR或DIFF。我想在本例中,variablecontentpath的值只是“”。所以在默认情况下,如果glob没有有效的内容路径,它会假定卷的驱动器号或根路径?因为\$回收站总是出现在卷的根级别。在

感谢大家的帮助:):):)


Tags: from路径dataifosjobthiswill
1条回答
网友
1楼 · 发布于 2024-10-01 04:53:03

与其他打开文件的用户无关。在

(一)shutil.copyfile文件一次复制一个文件。 2) 使用环球网查找要复制的所需文件集

# We'll be using this function to specify the buffer size:


def copyLargeFile(src, dest,buffer_size=16000):
       with open(src, 'rb') as fsrc:
            with open(dest, 'wb') as fdest:
                  shutil.copyfileobj(fsrc, fdest, buffer_size) 

相关问题 更多 >