I’m trying to get the number of files in a folder that have the same name. I’m using the following script which works for a folder on my desktop. But when I try a different folder I get the message “Can’t Find Folder”. I’ve tried different delimiters, I’ve tried different folders and I always get the same error message. I’m certain this is something simple I’m just missing.
property baseFileName : "EndiveName"
set targetDir to "/Applications/Endive Clients/"
tell application "Finder"
set fileCount to count of (files in folder targetDir whose name contains baseFileName)
end tell
AppleScript works, by default, with HFS paths. To use a UNIX-style path you need to indicate that using the POSIX path class:
property baseFileName : "EndiveName"
set targetDir to POSIX file "/Applications/Endive Clients/"
tell application "Finder"
set fileCount to count of (files in folder targetDir whose name contains baseFileName)
end tell
Note, the equivalent HFS path includes the drive name: "Macintosh HD:Applications:Endive Clients:".