2

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)

1 Answer 1

3

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
        --> 7
    count every folder of desktop
        --> 3
    count desktop
        --> 10
    count every file of desktop
        --> 7
    count every folder of desktop
        --> 3
end tell

Result:
10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .