How to Check if a Folder Contains Subfolders?

I thought that this would be simple but I cannot find any ready-made command to check whether a folder contains any subfolders (e.g. at the IF action).

How can I solve this task?

Perhaps something like this ?

has subfolders ?.kmmacros (23.4 KB)

1 Like

Hey Hans,

This job is relatively easy but tedious to do with native Keyboard Maestro actions.

Easier with AppleScript:

Count of SubFolders in a Target Folder (AppleScript) v1.00.kmmacros (6.9 KB)

It would be simple to do with the shell, except that various file-types on the Mac are actually directories that present to the user as files.

Like apps, rtfd files, scptd files...

-Chris

1 Like

Thanks, Chris, but in this case the solution of @ComplexPoint was already perfect :). (Background: I'm working on a macro that lets me move any selected file from the Desktop to one of my favourite folders, or, if no file is selected, open one of these folders.)

Hey Hans,

I have such a macro built already, but it's not quite friendly enough to be published.

I will post it to the forum when I have time.

It's similar to this:

-Chris

Hey Chris,

This is one of those cases that I'd argue that the KM non-script solution is easier to create and understand.

While your AppleScript is short, it is NOT simple unless you already have a very good understanding of how to use System Events with files/folders.

So, while it is simple for you, it is probably not for many others. :wink: