Looping through folders

Hi all:
I’ve written a script which loops through a folder and it works fine. However, when I display the items (see script below - they are all folders) it appears that though AS is sequencing through the folders it is not doing so alphabetically or by date created or modified. Was just curious why this is so and if there is a fix one could do to loop through the items alphabetically.
Thanks
Steve


set thePath to the folder "merion_image_archive" of folder "Cumulus_Test" of folder "WebDesign" of disk "WWW"
set theFileCount to (count of every item of thePath) sort by name
repeat with i from 1 to theFileCount
set fileType to file type of item i of thePath
if fileType = "fold" then
set itemNum to i as string
display dialog itemNum & return & name of item i of thePath & return & (count of every item of item i of thePath)
set folderItemCount to count of every item of item i of thePath
if folderItemCount > 0 then
set folderItemCount to count of every item of item i of thePath
end if
end if
end repeat

Posted the wrong script:
Remove this line:

 set theFileCount to (count of every item of thePath) sort by name
and replace with:
set theFileCount to (count of every item of thePath)

(We were trying to resolve the problem by applying a sort to the count - didn’t work)

Try this:

set theFldr to choose folder
tell application "Finder"
        set itemList to sort (items of theFldr) by name
end tell
repeat with anItem in itemList
        tell application "Finder" to set itemName to name of anItem
        display dialog itemName
end repeat

Marc K. Myers