Joe
Joe

Reputation: 102

Applescript: return list of subdirectories with full path

I have an Excel workbook with VBA code that needs to return a list of all sub-directories within a specified directory. It works fine using either Dir (or the FileSystemObject) on my Windows PC.

Unfortunately, the person I am writing the code for is using a Mac and neither solution has worked (obviously FileSystemObject would be unavailable on Mac OS, and the Dir command is returning only a "." or system files instead of directories).

I would like to try another approach using the VBA function MacScript, which is able to run Applescript. I have no idea how to code in Applescript and am asking for help writing a script that will take a directory (e.g. "/Test Dir") and return a list of all the sub-directories with their full paths (e.g. "/Test Dir/Sub1, /Test Dir/Sub2").

Any help would be greatly appreciated.

Upvotes: 1

Views: 504

Answers (1)

vadian
vadian

Reputation: 285059

A very efficient way is to use the find command of the shell. It's much faster than any native AppelScript way like telling the Finder to do the job

set folderList to paragraphs of (do shell script "/usr/bin/find '/Test Dir' -type d")

The single quotes around the path are required if the path contains space characters.

Upvotes: 1

Related Questions