Jump to content
Sign in to follow this  
digitalexpl0it

Help with Nested For loop

Recommended Posts

digitalexpl0it

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

Share this post


Link to post
Share on other sites
digitalexpl0it

doh, maybe thats why it skips it. now to figure out how to exclude sub directories per ini file

Share this post


Link to post
Share on other sites
digitalexpl0it

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

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  

  • Similar Content

    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • MrCheese
      By MrCheese
      Hi guys,
       
      Wondering, is there a better way, likely to use 'for...next' to add a letter to each range, by moving right -> along a range of columns in excel.
      I currently use this, but its clunky.
      If $run = 1 Then $range = "B6:B41" If $run = 2 Then $range = "C6:C41" If $run = 3 Then $range = "D6:D41" If $run = 4 Then $range = "E6:E41" If $run = 5 Then $range = "F6:F41" If $run = 6 Then $range = "G6:G41" If $run = 7 Then $range = "H6:H41" If $run = 8 Then $range = "I6:I41" If $run = 9 Then $range = "J6:J41" If $run = 10 Then $range = "K6:K41" If $run = 11 Then $range = "L6:L41" If $run = 12 Then $range = "M6:M41" If $run = 13 Then $range = "N6:N41" If $run = 14 Then $range = "O6:O41" If $run = 15 Then $range = "P6:P41" If $run = 16 Then $range = "Q6:Q41" If $run = 17 Then $range = "R6:R41" If $run = 18 Then $range = "S6:S41" If $run = 19 Then $range = "T6:T41" If $run = 20 Then $range = "U6:U41" If $run = 21 Then $range = "V6:V41" If $run = 22 Then $range = "W6:W41" If $run = 23 Then $range = "X6:X41" If $run = 24 Then $range = "Y6:Y41" If $run = 25 Then $range = "Z6:Z41" If $run = 26 Then $range = "AA6:AA41" If $run = 27 Then $range = "AB6:AB41" If $run = 28 Then $range = "AC6:AC41" If $run = 29 Then $range = "AD6:AD41" If $run = 30 Then $range = "AE6:AE41" If $run = 31 Then $range = "AF6:AF41" If $run = 32 Then $range = "AG6:AG41" If $run = 33 Then $range = "AH6:AH41" If $run = 34 Then $range = "AI6:AI41" If $run = 35 Then $range = "AJ6:AJ41" If $run = 36 Then $range = "AK6:AK41" If $run = 37 Then $range = "AL6:AL41" If $run = 38 Then $range = "AM6:AM41" If $run = 39 Then $range = "AN6:AN41" If $run = 40 Then $range = "AO6:AO41" If $run = 41 Then $range = "AP6:AP41" If $run = 42 Then $range = "AQ6:AQ41" If $run = 43 Then $range = "AR6:AR41" If $run = 44 Then $range = "AS6:AS41" If $run = 45 Then $range = "AT6:AT41" If $run = 46 Then $range = "AU6:AU41" If $run = 47 Then $range = "AV6:AV41" If $run = 48 Then $range = "AW6:AW41" If $run = 49 Then $range = "AX6:AX41" If $run = 50 Then $range = "AY6:AY41"  
      Normally, if it was going down the rows, i'd use this:
       
      For $i = 0 To UBound($iRowCount) - 1 $row = $i + 1 $range = "B"&$row&":B"&$row+1 Next  
      so something like this, but i don't know how to code sequential columns:
      For $i = 0 To UBound($iColCount) - 1 $col = $i + 1 $range = $col&"1:"&$col&"40" Next  
      If I don't make sense, let me know.
      Any help would be great. thanks
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
×