How to count files in a folder using AppleScript? How can I count files (without subdirectories) of a certain folder in AppleScript?

How can I count subdirectories (without files) of a certain folder in AppleScript?

How can I count both files and subdirectories of a certain folder in AppleScript?

For example:

count files of folder "Desktop" of home
count folders of folder "Desktop" of home
set variable to (count files of folder "Desktop" of home) + (count folders of folder "Desktop" of home)
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