AutoIt scripts runs without error but I can't see archive?

Posted by Scott on Stack Overflow See other posts from Stack Overflow or by Scott
Published on 2010-05-19T16:58:01Z Indexed on 2010/05/19 17:00 UTC
Read the original article Hit count: 588

Filed under:
|
#include <File.au3>
#include <Zip.au3>

; bad file extensions
Local $extData="ade|adp|app|asa|ashx|asp|bas|bat|cdx|cer|chm|class|cmd|com|cpl|crt|csh|der|exe|fxp|gadget|hlp|hta|htr|htw|ida|idc|idq|ins|isp|its|jse|ksh|lnk|mad|maf|mag|mam|maq|mar|mas|mat|mau|mav|maw|mda|mdb|mde|mdt|mdw|mdz|msc|msh|msh1|msh1xml|msh2|msh2xml|mshxml|msi|msp|mst|ops|pcd|pif|prf|prg|printer|pst|reg|rem|scf|scr|sct|shb|shs|shtm|shtml|soap|stm|url|vb|vbe|vbs|ws|wsc|wsf|wsh"
Local $extensions = StringSplit($extData, "|")

; What is the root directory?
$rootDirectory = InputBox("Root Directory", "Please enter the root directory...")

archiveDir($rootDirectory)

Func archiveDir($dir)

    $goDirs = True
    $goFiles = True

    ; Get all the files under the current dir
    $allOfDir = _FileListToArray($dir)
    Local $countDirs = 0
    Local $countFiles = 0

    $imax = UBound($allOfDir)
    For $i = 0 to $imax - 1
        If StringInStr(FileGetAttrib($dir & "\" & $allOfDir[$i]),"D") Then
            $countDirs = $countDirs + 1
        ElseIf StringInStr(($allOfDir[$i]),".") Then
            $countFiles = $countFiles + 1
        EndIf   
    Next

    MsgBox(0, "Value of $countDirs in " & $dir, $countDirs)
    MsgBox(0, "Value of $countFiles in " & $dir, $countFiles)

    If ($countDirs > 0) Then
        Local $allDirs[$countDirs]
        $goDirs = True
    Else
        $goDirs = False
    EndIf

    If ($countFiles > 0) Then
        Local $allFiles[$countFiles]
        $goFiles = True
    Else
        $goFiles = False
    EndIf

    $dirCount = 0
    $fileCount = 0

    For $i = 0 to $imax - 1
        If (StringInStr(FileGetAttrib($dir & "\" & $allOfDir[$i]),"D")) And ($goDirs == True) Then
            $allDirs[$dirCount] = $allOfDir[$i]
            $dirCount = $dirCount + 1
        ElseIf (StringInStr(($allOfDir[$i]),".")) And ($goFiles == True) Then
            $allFiles[$fileCount] = $allOfDir[$i]
            $fileCount = $fileCount + 1
        EndIf   
    Next

    ; Zip them if need be in current spot using 'ext_zip.zip' as file name, loop through each file ext.
    If ($goFiles == True) Then 
        $emax = UBound($extensions)
        $fmax = UBound($allFiles)
        For $e = 0 to $emax - 1
            For $f = 0 to $fmax - 1
                $currentExt = getExt($allFiles[$f])
                If ($currentExt == $extensions[$e]) Then
                    $zip = _Zip_Create($dir & "\" & $currentExt & "_zip.zip")
                    _Zip_AddFile($zip, $allFiles[$f])
                EndIf
            Next
        Next
    EndIf

    ; Get all dirs under current DirCopy

    ; For each dir, recursive call from step 2

    If ($goDirs == True) Then
        $dmax = UBound($allDirs)
        $rootDirectory = $rootDirectory & "\"
        For $d = 0 to $dmax - 1
            archiveDir($rootDirectory & $allDirs[$d])
        Next
    EndIf

EndFunc

Func getExt($filename)

        $pos = StringInStr($filename, ".")
        $retval = StringTrimLeft($filename, $pos + 1)
        Return $retval

EndFunc

This should output the .zip archives in the directories it finds the files that it needs to zip but it doesn't. Is there something I have to do after I create and add files to the archive within the code to put this created archive in the directory?

© Stack Overflow or respective owner

Related posts about autoit

Related posts about zip