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