What is the exact error you are getting? Your code seems to work fine for me.
If I understand correctly, you have one main archive that consists of multiple
archives, and you want to unpack the contents of those packed archives into a
target location?
The only change I made to your code before test, was this, since I am on OSX.
But it is probably best to do this anyways to be portable:
for files in tempfiles:
tzf = zipfile.ZipFile(os.path.join(temp_dir, files))
I compressed some files into two zip files, then compressed those into one main
one. It ran and extracted the files all into the target directory.
On Dec 7, 2012, at 12:48 AM, Jamie Telford wrote:
> Hi I'm running a script to unzip some files into a temp directory and then
> delete the temp directory once finished..
> however It seems that the current unzipping process hasn't completed yet and
> throws and error when my context manager tries to remove the temp directory..
> below is my code..
>
>
> @contextlib.contextmanager
> def make_temp_directory():
> temp_dir = tempfile.mkdtemp()
> yield temp_dir
> shutil.rmtree(temp_dir)
>
> def process(*args):
> zipPath = cmds.textField("zipInputField", q = True, text = True)
> outLoc = cmds.textField("outputField", q = True, text = True)
>
> # unpack files with *.zip extension from zip file to temp directory
> with make_temp_directory() as temp_dir:
> zf = zipfile.ZipFile(zipPath, 'r')
> for fileName in zf.namelist():
> if fileName.endswith(".zip"):
> zf.extract(fileName, temp_dir)
>
> # unpack zip files in temp directory to new folder location
> tempfiles = os.listdir(temp_dir)
> for files in tempfiles:
> tzf = zipfile.ZipFile(temp_dir + "\\" + files)
> tzf.extractall(outLoc)
>
> Cheers in advance!
>
> Jamie
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].