No nonsense approach:
dim file_list()
FileList( "*", file_list )
i=0
While 1
' Do some stuff with the current entry: FileRename( olddir & file_list(i), newdir & newname )
' placeholder:
MsgBox( file_list(i) )
i=i+1
Wend
This will lead to an error when all entries have been processed and you're trying to access an index outside the array boundaries. Now you can trap this expected error with an "On error" statement, but this will also trap unexpected errors (e.g. attempting to move a locked file). You might therefore want to use one of the following two variations:
1. Grow (or shrink) the array to a fixed size
dim file_list()
FileList( "*", file_list )
redim preserve file_list ( 0 to 999 ) ' keyword preserve leaves content inside
i=0
While ( ( i<1000 ) and len( file_list(i) ) )
....
i=i+1
Wend
2. Use sort functions to determine the last entry and use that value to break out at the right time
dim file_list()
FileList( "*" , file_list )
SortArray( file_list , 1 , 1 ) ' reverse sort places highest value at index 0
lastfile=file_list( 0 )
SortArray( file_list , 1 , 0 ) ' normal sort moves highest value to the last index
i=0
morefiles=-1
While morefiles
...
morefiles=compare( file_list(i) , lastfile )
i=i+1
Wend
Or you can use "for each"