Jump to content

Stuck For... Next loop


 Share

Go to solution Solved by Danp2,

Recommended Posts

HI Guys 

Once again, I think (I hope) i just need some fresh eyes to tell me what im missing here

I wrote a script to step through the user profiles on a remote PC and clear out the temp files (that bit seems to work)

I wanted to ad a bit at the end to clear the windows temp folder on the remote PC at the same time so i added this chunk form the already working code for the individual user temp files

Local $FileList = _FileListToArray($windowsTemp,"*")
    If @error = 1 Then
        MsgBox(0, "", "No Folders Found.")
    EndIf
    If @error = 4 Then
        MsgBox(0, "1", "No Files Found.")
    EndIf
    _ArrayDisplay($FileList)
    
    For $element In $FileList
        $isDir = FileGetAttrib($windowsTemp&"\"&$FileList[$element])
        If StringInStr($isDir, "D") Then
            $size = DirGetSize($windowsTemp&"\"&$FileList[$element])
            if $size = 0 then DirRemove($temppath&"\"&$FileList[$element])
        Else
            FileDelete($windowsTemp&"\"&$FileList[$element])
            MsgBox(0,"",$windowsTemp&"\"&$FileList[$element]) ;diagnostic
        EndIf
    Next

The file list populates with the directory listing as expected and the array display lists the entire directory listing as expected

The diagnostic message box will give the correct path and then gets stuck on element 0

It then gets stuck in an infinite loop bringing up a message box with targetpcc$windowstemp486 

486 being the number of files in the temp folder

I'm sure I'm missing something silly that's making it stick but I'm now at the point I cant see it for staring at it

Thanks

Grant 

Link to comment
Share on other sites

  • Moderators

Element 0 of _FileListToArray is the number of files found.

As stated by Danp2, your use of For/In is incorrect.

Instead of this:

For $element In $FileList

Try this:

For $element = 1 To Ubound($FileList) - 1

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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