zip
파일의 모든 .xls
파일을 식별하기 위해 네트워크 디렉토리를 반복적으로 검색하려고합니다. 파일 zip
에있는 XLS
파일마다 로컬 위치 C:
에 복사하고 싶습니다. 지금까지 내 스크립트는 다음과 같습니다.Python의 zipfile 내용 복사
import os
import zipfile
import fnmatch
import shutil
rootPath = "L:\Data\Cases"
destPath = "C:\Test"
allFileList = []
zipList = []
# Create a list containing all files contained within L:\Data\Cases
for dirname, dirnames, filenames in os.walk(rootPath):
for filename in filenames:
allFileList.append(os.path.join(dirname, filename))
# Return a list of filepaths containing zipfiles.
for file in allFileList:
if file.endswith(".zip"):
zipList.append(file)
for file in zipList:
with zipfile.ZipFile(file) as zip_file:
for member in zip_file.namelist():
if member.endswith(".xls"):
filename = os.path.basename(member)
if not filename:
continue
source = zip_file.open(member)
target = os.path.join(destPath, filename)
shutil.copy2(source, target)
오류 코드는 다음과 같습니다. 나는 압축 된 컨테이너에있는 파일이 실제로 대상 경로에 복사 됨으로 인해 오류가 발생했다고 생각합니다.
Traceback (most recent call last):
File "C:/Users/user/Desktop/parsecsv.py", line 30, in <module>
shutil.copy2(source, target)
File "C:\Program Files\Python278\lib\shutil.py", line 130, in copy2
copyfile(src, dst)
File "C:\Program Files\Python278\lib\shutil.py", line 68, in copyfile
if _samefile(src, dst):
File "C:\Program Files\Python278\lib\shutil.py", line 63, in _samefile
return (os.path.normcase(os.path.abspath(src)) ==
File "C:\Program Files\Python278\lib\ntpath.py", line 487, in abspath
path = _getfullpathname(path)
의견이 있으십니까?
'ROOTPATH = "L : \ 데이터 \".?. '(큰 따옴표) 문자를 탈출 – Nilesh
당신이 편집하고 오류를 표시 할 수 있습니다 그것은 도움이 될 –
을 "마지막으로 할 약간의 변화로 편집하고 최신 오류 – thefragileomen