Jump to content

Help with Nested For loop


Recommended Posts

Hello,

 

I am trying to updated a autoit app that moves files from one location to another. What Ia m trying to do is exclude specified sub directories from being moved/copied or files within the sub-folders

As of now the code doesn't want to execute the nested for loop 

 

Global $szDrive, $szDir, $szFName, $szExt
Global $File = "*"

func File_mover($Src,$File,$Dst)
    ; GET DIRECTORY EXCLUDES
    ; ######################
    
    ; Create blank 2 dem array
    Local $ExArray[0][1]
    ; load ini file
    Local Const $sFilePath = "exclude.ini"
    ; Check to see if ini exists
    Local $iFileExists = FileExists($sFilePath)
    ; If the INI file is not found, output error message
    If not $iFileExists Then
        msgbox(0,"Oh NO!", $sFilePath & " not found!")
    endif
    ; Read ini file
    Local $aArray = IniReadSection($sFilePath, "test")
    ; Start the array loop
    If Not @error Then
        for $i = 1 to $aArray[0][0]
            ; Add Ini values into array
            _ArrayAdd($ExArray, $aArray[$i][1])
        next
    endif
    ; Display array
    ;_ArrayDisplay($ExArray, "test Label")


    ProgressOn("Moving Scanned File(s)", "Moving scans into citrix...", "0%")

    $aFiles = _FileListToArray3($Src, $File, 1, 1, 0, 0)

    For $i = 1 To $aFiles[0]
        call("_PathSplit",$aFiles[$i], $szDrive, $szDir, $szFName, $szExt)
        $SrcFile = $Src & "\" & $szDrive & $szDir & $szFName & $szExt
        $DstFile = $Dst & "\" & $szDir & $szFName & $szExt

        $NumFiles = DirGetSize($Src,1)
        ; If File Exsists copy and rename file
        If FileExists($DstFile) Then
            $DstFile = call("_IfIdenticalIncrement", $SrcFile, $DstFile)
            If $DstFile <> "" Then
                For $ii = $NumFiles[1] To 100 Step 10
                    ProgressSet($ii, $ii & "%","Moving Files...")
                    ; Move Scans
                    
                    ; List Dir in srouce dir
                    $dirEx = _FileListToArray($Src,"*",2)
                    If UBound($dirEx) > 1 Then
                        ; Look in the dir list array
                        For $dir In $dirEx
                            ; Find and compaire dir in exclude array
                            For $exclude In $ExArray
                                If ($dir = $exclude) Then
                                    ; if exclude dir found go to top loop and skip
                                    ContinueLoop 2
                                EndIf
                            Next
                            FileMove($SrcFile, $DstFile, 8)
                        Next
                    endif
                    
                    Sleep(100)
                Next
            EndIf
            ; File doesnt exists so copy the file over
        Else
                For $ii = $NumFiles[1] To 100 Step 10
                    ProgressSet($ii, $ii & "%","Moving Files...")
                    ; Move Scans
                    
                    ; List Dir in srouce dir
                    $dirEx = _FileListToArray($Src,"*",2)
                    If UBound($dirEx) > 1 Then
                        ; Look in the dir list array
                        For $dir In $dirEx
                            ; Find and compaire dir in exclude array
                            For $exclude In $ExArray
                                If ($dir = $exclude) Then
                                    ; if exclude dir found go to top loop and skip
                                    ContinueLoop 2
                                EndIf
                            Next
                            FileMove($SrcFile, $DstFile, 8)
                        Next
                    endif   
                    Sleep(100)
                next
        EndIf
        
    ProgressSet(100, "Scans Moved...Successfully!", "Done!")
    sleep(2000)
    ProgressOff()
    Next
endfunc

Func _IfIdenticalIncrement($vSrcFile, $vDstFile)
    Local $Count = 0
; Get the modified date of the source file.
    $ScrVer = FileGetTime($vSrcFile, 0, 1)

; To get all elemnt of the distination file (in plan to add incremental number).
    call("_PathSplit",$vDstFile, $szDrive, $szDir, $szFName, $szExt)

; Loop to increment the name of the file.
    While FileExists($vDstFile)
        $Count += 1
        $vDstFile = $szDrive & $szDir & $szFName & "(" & $Count & ")" & $szExt
    WEnd

; If file(1), it assume that is the first copy.
    If $Count = 1 Then
        Return $vDstFile
; If file(x-1) is identical then assume the file is already duplicated.
    ElseIf $ScrVer = FileGetTime($szDrive & $szDir & $szFName & "(" & $Count - 1 & ")" & $szExt, 0, 1) Then
        Return ""
; Else assume it is a new version.
    Else
        Return $vDstFile
    EndIf
EndFunc  ;==>_IfIdenticalIncrement

 

 

This part is skipped and not sure why

 

For $exclude In $ExArray
                                If ($dir = $exclude) Then
                                    ; if exclude dir found go to top loop and skip
                                    ContinueLoop 2
                                EndIf
                            Next

INI file is this

 

[test]
EXCLUDE1=test1
EXCLUDE2=test2
EXCLUDE3=test3

 

Edited by digitalexpl0it
Link to comment
Share on other sites

that was it, I ended up tweaking the ini file to look like this

[test1]
[test2]
[test3]

 

which is fine since they will be directory names

then changed the following code to

 

; Read ini file
    Local $aArray = IniReadSectionNames($sFilePath)
    ; Start the array loop
    If Not @error Then
        for $i = 1 to $aArray[0]
            ; Add Ini values into array
            _ArrayAdd($ExArray, $aArray[$i])
        next
    endif

thanks for your help

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

×
×
  • Create New...