Apologies in advance if this question is already answered in the Forum ... I couldn't find it.

I am writing a script to perform file maintenance / cleanup. Specifically, I need to enumerate the user profile folders (c:\users\*) and then look for some specific folders under each user profile folder ... and then delete them. I am working on getting the folder enumeration code working properly before adding the delete routine. I have a placeholder for that right now.

According to the documentation, the DIR() function can enumerate a second folder by adding index 1 [i.e., $filename = dir($path,1)] but this does not seem to work. The script only "sees" the first profile folder (administrator), logs the first instance and then logs the other profile folders.

c:\users
\Administrator
\DeskAlerts_{6BD65F13-DD7D-436b-A232-CD8AF199B58B}
\All Users
\Default
\Default User
\desktop.ini
\jdoe
\MSSQL$ADK
\Public

If I remove the second folder code, it enumerates all of the User Profile folders just fine.

c:\users
\Administrator
\All Users
\Default
\Default User
\desktop.ini
\jdoe
\MSSQL$ADK
\Public

If I remove the index 1 option, it enumerates the first user profile correctly and then quits. It never looks at the other profile.

c:\users
\Administrator
\DeskAlerts_{6BD65F13-DD7D-436b-A232-CD8AF199B58B}
\DeskAlerts_{81EEE9F2-B5CE-458d-AA44-B6C723FB8379}
\DeskAlerts_{943F9A2C-5DB8-4030-BF2D-8F46AB738D9C}

Here is my code:

 Code:
; ===== VARS =====
$rootdir = "c:\users"
$rootdir ?  ; log the root dir

; ===== LOOP: PROFILE FOLDER =====
$filename1 = dir($rootdir)
while $filename1 <> "" and @error = 0
   if $filename1 <> "." and $filename1 <> ".."
      "   \" + $filename1 ?   ; log the profile folder

      ; ===== LOOP: APPDATA =====
      $filename2 = dir($rootdir + "\" + $filename1 + "\appdata\roaming\deskalerts_*",1)
      while $filename2 <> "" and @error = 0
         "      \" + $filename2 ?   ; log the deskalerts_* folder

         ; insert delete_folder code here

         $filename2 = dir()
      loop

   endif
   $filename1 = dir()
loop


... and here is what the DOS dir command shows:

c:\>dir c:\users\deskalerts_* /a/s/b

C:\Users\Administrator\AppData\Roaming\DeskAlerts_{6BD65F13-DD7D-436b-A232-CD8AF199B58B}
C:\Users\Administrator\AppData\Roaming\DeskAlerts_{81EEE9F2-B5CE-458d-AA44-B6C723FB8379}
C:\Users\Administrator\AppData\Roaming\DeskAlerts_{943F9A2C-5DB8-4030-BF2D-8F46AB738D9C}
C:\Users\Default\AppData\Roaming\DeskAlerts_{6BD65F13-DD7D-436b-A232-CD8AF199B58B}
C:\Users\Default\AppData\Roaming\DeskAlerts_{81EEE9F2-B5CE-458d-AA44-B6C723FB8379}
C:\Users\Default\AppData\Roaming\DeskAlerts_{943F9A2C-5DB8-4030-BF2D-8F46AB738D9C}
C:\Users\jdoe\AppData\Roaming\DeskAlerts_{1CE89CDA-77BA-4cbd-BD52-C32F884C3ECA}
C:\Users\jdoe\AppData\Roaming\DeskAlerts_{6BD65F13-DD7D-436b-A232-CD8AF199B58B}
C:\Users\jdoe\AppData\Roaming\DeskAlerts_{81EEE9F2-B5CE-458d-AA44-B6C723FB8379}
C:\Users\jdoe\AppData\Roaming\DeskAlerts_{881F9EA6-B6B9-45c4-8F0D-5EEFAD04CFBE}
C:\Users\jdoe\AppData\Roaming\DeskAlerts_{943F9A2C-5DB8-4030-BF2D-8F46AB738D9C}
C:\Users\MSSQL$ADK\AppData\Roaming\DeskAlerts_{6BD65F13-DD7D-436b-A232-CD8AF199B58B}
C:\Users\MSSQL$ADK\AppData\Roaming\DeskAlerts_{81EEE9F2-B5CE-458d-AA44-B6C723FB8379}
C:\Users\MSSQL$ADK\AppData\Roaming\DeskAlerts_{943F9A2C-5DB8-4030-BF2D-8F46AB738D9C}

Kix ver: 4.62 and 4.64
O/S: Windows 7, SP1, 32-bit

TIA for any advice on this.