[Closed] maxunzip woes
Hi,
I've been using maxzip to zip files in most of my scripting projects successfully. A new project calls for some files to be unzipped. I tried to use maxunzip, but couldn't get it to work from within maxscript.
This is what I tried. Make sure you've got a file testdata.zip in the c: emp folder to actually test this code.
sourcePath = @"C:\Temp\TestData.zip"
unzipUtil = (getDir #maxRoot) + "maxunzip.exe"
cmd = "" as stringStream
format "\"%\" \"%\"" unzipUtil sourcePath to:cmd
hiddendosCommand (cmd as string) exitcode:&exitcode
print exitcode
This returns the exitcode 1 (instead of 0) and doesn't actually unzip the file. When I use the exact same commandstring and paste it in a regular dos box, the file gets unzipped just fine.
Does anyone have experience with this?
use direct slashes instead of backslashes
sourcePath = @"C:/Temp/Temp.zip"
Thanks Denis, I’ve tried the following
sourcePath = @"C:/Temp/TestData.zip"
unzipUtil = @"C:/Program Files/Autodesk/3ds Max 2013/maxunzip.exe"
cmd = "" as stringStream
format "\"%\" \"%\"" unzipUtil sourcePath to:cmd -- thanks to ofer_z--zipFile needs to be a mapped drive: yes
hiddendosCommand (cmd as string) exitcode:&exitcode
print exitcode
But it gives me the exact same result: it doesn’t unzip anything. I’ve tried it in max 2014 and 2013 by the way.
i’ve tried it in 2012 and 2014. both work right. (actually with backslashes as well)
edited…
Thanks Denis for verifying that it should work.
I’ve tried Lo’s suggestion and implemented something based on this. And it works!
sourcePath = @"C:/Temp/TestData.zip"
unzipUtil = @"C:/Program Files/Autodesk/3ds Max 2013/maxunzip.exe"
cmd = "" as stringStream
format "\"%\"" sourcePath to:cmd -- thanks to ofer_z--zipFile needs to be a mapped drive: yes
procStartInfo = dotnetObject "System.Diagnostics.ProcessStartInfo" unzipUtil (cmd as string) --setup the actual command
procStartInfo.RedirectStandardOutput = true
procStartInfo.UseShellExecute = false
procStartInfo.CreateNoWindow = true
proc = dotnetObject "System.Diagnostics.Process"
proc.StartInfo = procStartInfo
proc.Start()
result = proc.StandardOutput.ReadToEnd()
print result
Check out the link for more info, but this acts similar to hiddendoscommand. thanks for the idea Lo!
I’d like to add that it seems wise to add
proc.WaitForExit()
after
proc.start()
If code depends on files being unzipped we have to wait for this process to finish.
One more thing: when using maxunzip, either from within maxscript or directly from the commandline, I’m unable to retain the original folder structure from the zip. All files in the zip are just extracted onto one flat pile of files.
This resembles the behaviour of PKUNZIP described here.
For example, UnZip recreates the stored directory structure by default; PKUNZIP unpacks all files in the current directory by default
Looking at some documentation for PKUNZIP there’s an option to retain the folderstructure in the zip-file. It’s the -d option. However, when I use that option, nothing is unzipped and a message is displayed (when using the commandline) saying the wrapper has been written by Larry Minton and that we can use it for free. It seems the use of any of the available options is blocked.
So to test that out , try something like this in the commandline:
"C:\Program Files\Autodesk\3ds Max 2014\maxunzip.exe" "somefile.zip" --this one produces a flat pile of files, ignoring the folders in the zipfile
"C:\Program Files\Autodesk\3ds Max 2014\maxunzip.exe" -d "somefile.zip" --nothing happens, just some message is displayed
"C:\Program Files\Autodesk\3ds Max 2014\maxunzip.exe" "somefile.zip" -d --just to be sure!
Can anyone confirm this? I think I have to resort to bundling an unzip utility with my script. Or is there a default .net unzip tool I’m overlooking?