to easily count how many files are in that folder. And I'm sure it can easily do that. But I haven't been able to find anything in the User Guide that tells how to do it... Can anybody help? Thanks!
You can use the
For Each Path in Folder action found in the Control Flow and File categories. This allows you to process each file (and folder) in the trigger folder without specifically needing to know how many there are.
But if you do want an actual number:
As you can see, there are 10 files (and folders) in this particular trigger folder.
You can also do it with AppleScript:
tell application "System Events" to get the number of items in folder "~/Example" whose visible is true
items refers to files and folders, and you can exchange this for the term
files or the term
folders to get a specific count for each (not that the
For Each... action mentioned above returns the count for both files and folders (collectively referred to as files or paths, so just mind the fuzzy terminology).
You can also do it with shell script:
ls ~/Example | wc -l
There is actually a separate topic where that question has been asked/answered, with a number of different solutions to choose from:
Only the small secrets need to be protected. The big ones are kept secret by public incredulity.
I know this is an old post, but according to what i understand the example above works with when the folder is set in advance. Is there a way you can ask the user which folder to work with, then count that folder?
Folder File Count.kmmacros (2.3 KB)
In addition to the excellent macro that @gglick provided, here is a macro which provides several means for specifying the Folder Path, and may be faster if there are many (>> 100) files in the folder:
It makes use of a fast, reusable Bash Shell Script:
Excellent! Thanks guys. If one were to filter the result to a specific file type, how would you go about it? (Sorry, total noob at KM, but love it so far)
In the type of macro I demonstrated, this can be accomplished by enclosing the action used to count the number of files with an If Then Else action. Using PDF files as an example:
Easy enough. Change two actions in my Macro:
Add FileExt Variable to Prompt
Add name Filter to find Command
find command is very powerful, and very compact to use.
For more info, see Bash Find Command Document