Jump to content
Sign in to follow this  

Stuck For... Next loop

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.")
    If @error = 4 Then
        MsgBox(0, "1", "No Files Found.")
    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])
            MsgBox(0,"",$windowsTemp&"\"&$FileList[$element]) ;diagnostic

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



Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Thanks Danp2 

That's got it

Sm0ke_N Ill have a look at ubound also.

Looping and arrays is always something that seems to break my brain

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  

  • Create New...