Building Folder Structures in the Finder with FileMaker Pro 17

In keeping with the principle, “Why use a screwdriver, when I have this hammer right here?”, I decided, instead of just downloading a free utility from the Mac App Store, I would build folder creation functionality using FileMaker Pro Advanced 17. With FileMaker 17’s new ability to “Create Directories” in the “Export Field Contents” step options, and an old trick to delete files from the OS, this demo file demonstrates a new and useful capability in FileMaker to create pre-defined folder structures, pretty much anywhere on your computer or related cloud directories.

The free Client Folder Maker was an inspiration for this demo file.

Client Folder Maker
There is a nice and free alternative to building folder structures on your hard drive from the Mac App Store. It is called ‘Client Folder Maker‘.

Bah! Dedicated software, why use an app when you can build it into FileMaker? The FileMaker 17 demo file below, allows you to create batches of folders on your desktop or other locations, including some cloud folders, such as Google Drive and Dropbox.

Download Demo File

Enter the folder names and their directory paths here.
There are three fields for each Folder.
• The Base Location
• The Folder Name
• Folder Set name.

When the user runs the script, they are prompted to enter a Year and Company name. 

The Folder Name field can handle three merge variables. These are:

• {Year} – the year for which you wish to generate the folders.
• {Month} – this variable generates 01-12 Month folders
• {Company} – this could be a company, organization or name.

The filter field at the top will allow users to quickly select different sets of folders.

A value list displays the options for the Base Location to save your Folder sets.

Select where the Base Location where the folder structure will appear.
The script value list offers the following options:
• Desktop
• Documents
• Dropbox – assumes you have an account and are logged in.
• File – this will put the folder next to your FileMaker file.
• Google Drive – assumes you have an account and are logged in.
• Temporary – kind of a useless location. Not easy to get to.

More options can be added to the value list. They must be added to $BasePath variable by adding to the Case statement in the Create Folder Structure script.

Merge fields are entered here, {Year}, {Month}, {Company}.
There are two merge variables created in the dialog box, one for Year and another for Company. If you enter a Month variable, 12 monthly folders will be generated using a loop. All are merge variables are optional. More merge variables could be added as needed. Alternatively, these variables could be determined, rather than in the dialog box, from another data table. For example Company could come from a Customer database, Year could be generated by the Current Year or the Current Year plus 1, etc.

In the Settings for this file is a small test file that gets used to create the directories. It is immediately deleted after the directory is created.

The Test File.
There is a test file PDF stored in the Settings popover. This small file is just there to create the folders. Once the folder is created, the file gets deleted. You can put your own file in here, but it won’t make any difference, because if all is working well, no one will ever see this file.
See the update at the bottom.

This script was fairly simple, until I added the Month variable routine. 

Create Folder Structure script.
Two FileMaker 17 features are required for this script. The most important is the Export Field Contents – Create Directories option turned on.

The second feature is not as essential, but nice to use, the ability to create a variable directly from a dialog box.

A key concept here is that we are using the FileMaker 17 ability to create a directory to place a file and then using an older FileMaker ability to delete the small test file right after it is created by Exporting Field Contents again, but this time, not selecting a field. FileMaker overwrites the file with ‘nothing’ and it gets deleted. 

Note the ‘Field is missing’ error. This is a good thing.

Key Step to Deleting the Temporary File
The second Export Field Contents does not specify a field, so it is empty and exports to the file name, Deleting it from the folder.

A new option in FileMaker 17 is the ability to input data from a Show Custom Dialog directly into a variable. No longer do developers need to create global fields to hold temporary data like this.

Setting Variables from a dialog box.
Thank you FileMaker Inc. This feature was a long time coming and we are grateful that it has arrived.

A Folder structure exported from FileMaker Pro 17. All the folders are empty. The merge fields for Year, Company and Month are filled in.

Folders created in the required location.
The end result of this script is a batch of folders created on the Desktop, or other Base Locations. As you can see, this is a fairly useful idea and could be adapted to a FileMaker workflow, wherever you need a folder structure built, either annually, or monthly or for a specific company.

Update 2018-12-12: At 5 am, the morning after posting this idea, while supposedly sleeping, apparently my brain was still processing a bit in the background and it occurred to me to test running the script without exporting the test file. Instead, just using a single Export Field Contents with no field specified and ‘Create Directories’ turned on, I found that it works! Presumably FileMaker’s function is creating the directories, before it checks to see if there is an actual file to export. This makes the script a little simpler, presumably a bit faster and no files are deleted in the process. I have updated the demo file, getting rid of the File container field for export and shortening the scripts by a line or two.

4 Responses to “Building Folder Structures in the Finder with FileMaker Pro 17”

  1. Really nice technique, thank you.

  2. Hammers = more fun

  3. Nice work Douglas (as always) and thanks for sharing it !

    Just a question, is there a way with FileMaker to know the content of a folder (file names and/or folder names) ?

    And last but not least …

    Merry Christmas !

%d bloggers like this: