2011-10-31 2 views
0

아직 존재하지 않는 하위 디렉토리를 작성한 다음 하위 디렉토리에 파일을 복사해야합니다. 그러나 시도 할 때마다 Permission denied 오류가 발생합니다. 777뿐만 아니라 stat.S_IWRITE와 chmod를 시도했는데 os.system ('attrib -r)을 시도했지만 아무 것도 작동하지 않습니다. 아무도 내가 이걸 해결하도록 도와 줄 수 없나요? 사이트에 비슷한 질문이 있다는 것을 알고 있지만 chmod를 사용한다고 나와 있습니다. chmod는 나를 위해 작동하지 않습니다. 내가 shutil.copyfile는 대상 파일의 전체 파일 이름뿐 아니라 디렉토리를 필요가 있다고 생각Python을 사용하여 Windows에서 쓰기 가능한 디렉토리 만들기 os.makedirs

beginpath = "C:\Users\foo" 
fullpath = os.path.join(beginpath, foldername) 
print fullpath 
fullpath = fullpath.replace('\n', '') 

##create a folder to hold the deleted files 
deleted = os.path.join(fullpath, "Deleted") 
print deleted 
if not os.path.exists(deleted): 
      os.makedirs(deleted) 
      os.chmod(deleted, stat.S_IWRITE) 
      print "created" 



##do some other processing here 


oldfile = os.path.join(fullpath, newpagename) 
shutil.copyfile(oldfile, deleted) 
+0

답변을 얻는다면, 그 사람이 어떤 점을 얻을 수 있도록 확인하십시오! –

답변

1

:

여기 내 코드입니다.

그래서

shutil.copyfile(oldfile, os.path.join(deleted, newpagename)) 

트릭을 할해야합니다.

+0

그게 효과가! 고마워요! – bsg

+0

... 또는'shutil.copy (oldfile, deleted)'를 사용하십시오. – Marvin

관련 문제