python - Get Local File name after ZipFile extract() -
how local file name after zipfile extract()
runs?
when this:
zipfile.zipfile(localzipfilepath, "r") zf: name in zf.namelist(): localfilepath = zf.extract(name, '/tmp/') print localfilepath
the file exists in zip file is: src/xyz/somefile.txt
localfilepath
outputs this: /tmp/src
the file written here: /tmp/src/xyz/somefile.txt
, in graceful way.
i think misunderstood something. zipfile.extract()
method returns either full path either directory or file created specific zipfile member.
the documentation doesn't state explicitly, source code method quite clear here:
if member.filename[-1] == '/': if not os.path.isdir(targetpath): os.mkdir(targetpath) return targetpath self.open(member, pwd=pwd) source, \ file(targetpath, "wb") target: shutil.copyfileobj(source, target) return targetpath
so either member filename ends in /
(a directory), in case directory created, or file created data being copied in. either way, targetpath
local path of filesystem entry created.
i've opened python issue have documentation updated; of 2015-03-15 documentation has been updated read:
returns normalized path created (a directory or new file).
Comments
Post a Comment