stev379 Posted May 5, 2010 Posted May 5, 2010 How can I extract msp files from cab files with AutoIT? I have 99 folders. Each folder may have at least 1 or more cab file. Each cab file has an msp. I've tried with VB using 'extract' or 'unzip.exe' and get nothing but syntax errors. I'm starting an attempt with AutoIT now, but can only work on it a few minutes at a time and wanted to see if anyone's been through this already. Thanks for any help or suggestions. I found similar but not close enough results after searching.
hawky358 Posted May 5, 2010 Posted May 5, 2010 Are all the folders a subfolders of a main folder? This is the approach I would take: - Use _FileListToArray() to get a list of all the files/folders in the main folder. - Use FileGetAttrib() to determine when you are dealing with a folder - Then use FileFindFirstFile() on the folders to search for cabs - Either make a list of all files to be extracted, or extract them on the spot using run() or _runDos() I'll write some sample code. But you can use that as a base .
PsaltyDS Posted May 5, 2010 Posted May 5, 2010 ...or extract them on the spot using run() or _runDos()Or maybe RunWait(), so you don't get dozens of extractions running simultaneously. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
hawky358 Posted May 5, 2010 Posted May 5, 2010 (edited) Or maybe RunWait(), so you don't get dozens of extractions running simultaneously.True though usually I prefer to use run() then use processlist() to count applications and only allow say 10 or whatever to run. I used Runwait in this example as recommended by PsaltyDS This will extract all .msp files from all cabs contained in the folder and the subfolders of the script. (The msp files are extracted to where the .cab is, but you can easily change that) *Note you need to get extract.exe youself if you don't have it MS Cab SDK expandcollapse popup#include <Array.au3> #include <File.au3> $fulllist = _FileListToArray(@Scriptdir) global $finallist[1] for $i = 0 to UBound($fulllist)-1 $attrib = FileGetAttrib($fulllist[$i]) if stringinstr($attrib,"D") = 0 Then ; It's a file LogFile($fulllist[$i]) Else ; It's a folder scanfolder($fulllist[$i]) EndIf Next for $i = 1 to UBound($finallist) -1 $folder = StringTrimRight($finallist[$i],stringlen($finallist[$i])-stringinstr($finallist[$i],"\",-1,-1)+1) RunWait('extract "' & $finallist[$i] & '" /e *.msp /l "' & $folder & '"') Next Func ScanFolder($folder) $Search = FileFindFirstFile($Folder & "\*.*") While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop EndIf $filelocation = $folder & "\" & $file $attrib = FileGetAttrib($filelocation) If StringInStr($attrib,"D") > 0 Then ScanFolder($filelocation) Else LogFile($filelocation) EndIf WEnd FileClose($Search) EndFunc Func LogFile($FileName) $ext = StringRight($filename,StringLen($filename)-StringInStr($filename,".",-1,-1)) if StringCompare($ext,"cab") = 0 Then _ArrayAdd($finallist,$filename) EndIf EndFunc edit: I always mess up the code box Edited May 5, 2010 by hawky358
stev379 Posted May 6, 2010 Author Posted May 6, 2010 True though usually I prefer to use run() then use processlist() to count applications and only allow say 10 or whatever to run. I used Runwait in this example as recommended by PsaltyDS This will extract all .msp files from all cabs contained in the folder and the subfolders of the script. (The msp files are extracted to where the .cab is, but you can easily change that) *Note you need to get extract.exe youself if you don't have it MS Cab SDK expandcollapse popup#include <Array.au3> #include <File.au3> $fulllist = _FileListToArray(@Scriptdir) global $finallist[1] for $i = 0 to UBound($fulllist)-1 $attrib = FileGetAttrib($fulllist[$i]) if stringinstr($attrib,"D") = 0 Then ; It's a file LogFile($fulllist[$i]) Else ; It's a folder scanfolder($fulllist[$i]) EndIf Next for $i = 1 to UBound($finallist) -1 $folder = StringTrimRight($finallist[$i],stringlen($finallist[$i])-stringinstr($finallist[$i],"\",-1,-1)+1) RunWait('extract "' & $finallist[$i] & '" /e *.msp /l "' & $folder & '"') Next Func ScanFolder($folder) $Search = FileFindFirstFile($Folder & "\*.*") While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop EndIf $filelocation = $folder & "\" & $file $attrib = FileGetAttrib($filelocation) If StringInStr($attrib,"D") > 0 Then ScanFolder($filelocation) Else LogFile($filelocation) EndIf WEnd FileClose($Search) EndFunc Func LogFile($FileName) $ext = StringRight($filename,StringLen($filename)-StringInStr($filename,".",-1,-1)) if StringCompare($ext,"cab") = 0 Then _ArrayAdd($finallist,$filename) EndIf EndFunc edit: I always mess up the code box Excellent!! Thank you for all the suggestions. I did change the destination folder and added a overwrite switch to extract. All is well in extraction land. Nicely done. -Steve
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