Jump to content

Extract multiple cab files containing multiple msp's


Recommended Posts

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.

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

...or extract them on the spot using run() or _runDos()

Or maybe RunWait(), so you don't get dozens of extractions running simultaneously.

:idea:

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
Link to comment
Share on other sites

Or maybe RunWait(), so you don't get dozens of extractions running simultaneously.

True :idea: 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

#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 by hawky358
Link to comment
Share on other sites

True :idea: 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

#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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...