Sign in to follow this  
Followers 0
slandau

Problem searching array for string

3 posts in this topic

So on line 71 it keeps setting @error even though the file extension does exist in the array as a String I hope. I have put in MsgBox's in a couple places in the code to see and $currentExt printed out definitely does exist in $extensions. Any ideas? This is kind of urgent.

#include <File.au3>
#include <Zip.au3>
#include <Array.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)
    $tmax = UBound($allOfDir)
    For $t = 0 to $tmax - 1
    Next
    
    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

    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 
        $fmax = UBound($allFiles)
        For $f = 0 to $fmax - 1
            $currentExt = getExt($allFiles[$f])
            $position = _ArraySearch($extensions, $currentExt)
            If ($position == -1) Then
                MsgBox(0, "Not Found", "Not Found")
            Else
                $zip = _Zip_Create($dir & "\" & $currentExt & "_zip.zip")
                _Zip_AddFile($zip, $dir & "\" & $allFiles[$f])
            EndIf
        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

Share this post


Link to post
Share on other sites



Is getExt() returning ".zip" with the leading dot? Your $extensions array doesn't appear to have the dots.

: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

Share this post


Link to post
Share on other sites

Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0