Jump to content

How to skip loop and go to next


Recommended Posts

For $i = 0 To UBound($ComputerName) - 1
    $iFileExists = FileExists("\\" & $ComputerName[$i] & "\C$\Temp\Agent15\install_agent.bat")
    If Not $iFileExists Then
Next
FileWriteLine($LogFile, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Running installer")
;I'm doing more stuff if the bat file exist.
Next

Hi

I am looping through a txt file with computer names and checking if the bat file exists on the remote computer if it does not how do I skip this computer "$ComputerName[$i]" and move on to the next and start from the beginning from "For"?

Link to comment
Share on other sites

  • Moderators

Why not just:

If FileExists("\\" & $ComputerName[$i] & "\C$\Temp\Agent15\install_agent.bat") Then
   ;Do something
EndIf

Then if the file doesn't exist, the PC is skipped.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

I guess I am confused as to what you're after. If you ExitLoop, however many machines remain in the array will not be checked. If you then start the For Loop again from the beginning, unless you're doing something else to remove that computer from the array, you're going to exit again as soon as the array comes to this same PC.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

2 minutes ago, antmar904 said:

I guess I'm ultimately trying to see if the pc is on before moving forward, I just thought of the ping.

Ping($ComputerName[$i])
    If @error Then
        ExitLoop
    EndIf

Will ExitLoop go back to the top of the loop and go through the rest of the computer names?

No.

Try ContinueLoop.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hello,

use ContinueLoop

For $i = 0 To UBound($ComputerName) - 1
    $iFileExists = FileExists("\\" & $ComputerName[$i] & "\C$\Temp\Agent15\install_agent.bat")
    If Not $iFileExists Then ContinueLoop

    FileWriteLine($LogFile, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Running installer")
    ;I'm doing more stuff if the bat file exist.
Next

 

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

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...