jben Posted April 17, 2008 Posted April 17, 2008 Hey everyone, Is it possible to extract a zip file in AutoIT. I have several zip files that I'm trying to extract. The problem I have is that these files are zip files within zip files. Therefore i'm trying to workout a way that I could create some code to extract these files to a specified directory. i.e test.zip within this zip file is test2.zip and within this is a folder therefore I want to somehow extract the folder within c:\test.zip\test2.zip\folder thanks
someone Posted April 17, 2008 Posted April 17, 2008 (edited) Someone (ha well not this someone) may be able to give you a working example outright, but check out this thread Edited April 17, 2008 by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
jben Posted April 17, 2008 Author Posted April 17, 2008 (edited) Thats rather useful and does work. Only problem I have is that I can't seem to get wildcards to work. The main issue I have is that the .zip file will not always have the same name in the C:\Hello" However this folder will always only contain the latest zip files, is there any way I could use some sort of wildcard to extract *.zip ?? as in the zip folder could contain hello1.zip and then at another point it could contain hello2.zip...and then possibly picture1.zip Therefore the code would work if hello.zip is in the folder but if this changes then the code wouldn't work :-( thanks and here is the code: #include-once #include<AutZip\_ZipPlugin.au3> $szZipFile = "c:\Hello\hello.zip" $szDestDir = "C:\Picture" $szPluginPath = @ScriptDir &"\Au3Zip.dll" $hPluginDll = PluginOpen($szPluginPath) If $hPluginDll = -1 Then MsgBox(266288,"Error:","Plugin not initialized.") Exit EndIf $aZipList = _ZipList2Array($szZipFile) for $x =0 to UBound($aZipList)-1 If StringLower(StringRight($aZipList[$x][1],4)) = ".zip" Then ConsoleWrite("Extracting:"&$aZipList[$x][1]) $vResult = _ZipUnZipItem($szZipFile,$aZipList[$x][1],$szDestDir) ConsoleWrite(" -- "&_ZipFormatMessage($ZR_RECENT)&@lf) EndIf Next PluginClose($hPluginDll) Edited April 17, 2008 by jben
someone Posted April 17, 2008 Posted April 17, 2008 I haven't used the zip plugin, but your saying you have a zip file with a lot of nested zips, and you want to extract them all? Can you extract the parent zip, and then do a _FileListToArray() to grab the file names? I'm a little confused by what your asking but you should be able to use FileFindFirstFile/FileFindNextFile or FileListToArray to get all the names of zip files you want to extract. Actually looking at the zip plugin thread what about ZipList2Array? Let me know if any that is helpful While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
jben Posted April 17, 2008 Author Posted April 17, 2008 (edited) The problem is that the parent zip name changes once a week. As in WeeklyUpdate17_04_08.zip and then a week later this file will then be known as WeeklyUpdate24_04_2008.zip So if we take this week as an example....which is WeeklyUpdate17_04_08.zip then this would contain several folders which all contain a .zip file which I want to extract to a folder. so the zip file is like this. WeeklyUpdate17_04_08.zip .....contains folder1 and folder2 ..........folder1 contains a zip ......................extract folder1 zip to c:\extracted Edited April 17, 2008 by jben
someone Posted April 17, 2008 Posted April 17, 2008 OK theres a bunch of ways to capture the path of the parent zip. You can use FileOpenDialog, or any of the methods I mentioned above. Depends on how you want to do it. There might be a better way to unzip the child zips, but what I would do (since I am not familiar with the zip UDF) is to unzip the parent zip to a temp directory, and then use FileListToArray to nab all the file names, and again use the zip UDF to unzip them all to the final destination (c:\extracted) and then delete the temp directory. As I said there may be a shorter way to do this with the UDF, but I know you can do it this way. Whatever you end up doing post it back here I'm curious what you come up with. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
jben Posted April 17, 2008 Author Posted April 17, 2008 I agree with you on that. Its probably the best way forward by extracting to a temp folder.. You mention "FileListToArray to nab all the file names" but what do you mean by this?. I have been thinking. I can extract the files to temp, but then I still need to extract the zips from the temp folder to get to the core of the files I require. Also the best way I can think of ensuring that the extraction works is to set something up at the beginning of the code that will rename the parent zip within the folder to something that the code can recognize(if thats possible)....then at the end of the code delete the parent zip. So everytime a new zip is copied to the folder, the program can be run and rename the zip and run the code...maybe something like that?..not sure
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now