2014-12-04 4 views
0

이것은 문제가 발생한 것으로 보이는 코드의 일부입니다. 일부 사용 권한이 누락 되었습니까?Python shutil.copy [오류 13] 사용 권한이 거부되었습니다.

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 

이것은 내가 얻는 오류입니다. 나는 휴지통을 복사하려고 아니에요 말씀 드릴 수 있습니다하지만 여전히

Traceback (most recent call last): 
    File "create&&bkp.py", line 26, in <module> 
    BackupSC.bkp_witout_inpv10() 
    File "C:\Users\dhiwakarr\workspace\basics\BackupSC.py", line 210, in bkp_witout_inpv10 
    addcontent(job,jobpath) # Add some Content : We need Job Type & Path to Create as parameters 
    File "C:\Users\dhiwakarr\workspace\basics\BackupSC.py", line 96, in addcontent 
    shutil.copy(file,jobpath) 
    File "C:\Python34\lib\shutil.py", line 228, in copy 
    copyfile(src, dst, follow_symlinks=follow_symlinks) 
    File "C:\Python34\lib\shutil.py", line 107, in copyfile 
    with open(src, 'rb') as fsrc: 
PermissionError: [Errno 13] Permission denied: '\\$Recycle.Bin' 

이 방법은 경로가 성공적으로 생성되었지만 다음에 내가이 오류라고 처음 실패합니다. 두 번째로 경로가 존재하는 이유는 무엇입니까?

UPDATE

마지막으로 내 바보 같은 실수를 알아 냈어. 작업에 전송 된 값은 FULL, INCREMENTAL & DIFFERENTIAL INCR 또는 DIFF가 아닙니다. 이 경우에는 변수 contentpath의 값이 ''였습니다. 따라서 glob에 유효한 내용 경로가 없으면 드라이브 문자 또는 볼륨의 루트 경로를 사용합니까? \ $ Recycle.Bin은 항상 볼륨의 루트 수준에 있기 때문에. 모든 도움의 사람들에 대한

감사합니다 :) :) :)

파일을 열어 잡고 다른 사용자와 관련이없는
+0

파일의 읽기 및 쓰기 권한이 있습니까 ?? 어떤 파일을 – Hackaholic

+0

? 내가 복사하고있는 파일들? 네 저도 그렇습니다. Explorer & \\ $ Recycle.Bin을 통해 복사 할 수있었습니다. 복사 할 대상이 아닙니다. 내가 뭔가를 삭제하려고했지만 줄 심지어 삭제 아니에요 –

+0

관리자로 실행 파이썬 스크립트 – Hackaholic

답변

1

.

1) shutil.copyfile은 한 번에 하나의 파일을 복사합니다. 2) glob.glob를 사용하여 복사 할 파일 집합을 찾습니다.

# 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) 
관련 문제