How to count files in a folder using AppleScript?
The following example AppleScript code:

tell application "Finder"
    count files of desktop
    count folders of desktop
    count items of desktop
    set variable to (count files of desktop) + (count folders of desktop)
    return variable
end tell


On my system currently produces the following results:

tell application "Finder"
    count every file of desktop
        --&gt; 7
    count every folder of desktop
        --&gt; 3
    count desktop
        --&gt; 10
    count every file of desktop
        --&gt; 7
    count every folder of desktop
        --&gt; 3
end tell

Result:
10