My.ADVISOR.com Sign-In
Username
Password
Sign Up 
Go to Article
Advanced Search 

ADVISOR TIPS

Create a FileMaker Pro Folder

Learn how to create a directory or folder on the local hard drive from a FileMaker file natively.

By John Mark Osborne, Database Pros president and owner, and FileMaker Advisor technical editor

UNLOCKED -- This article is provided to subscribers of FILEMAKER ADVISOR or DATABASED ADVISOR or FILEMAKER ADVISOR. To subscribe or renew, go to Advisor Store.

I've always wanted to be able to create a directory or folder on the local hard drive from a FileMaker file. Products such as the Troi File Plug-in (www.troi.com) are able to easily perform this task but it's also nice to know what your FileMaker Pro-only options are, because they don't require licensing a third-party product.

The big roadblock to storing a folder in FileMaker Pro is the limitations of a Container field. Container fields can only store files. The workaround is to compress an empty folder into a .ZIP or .SIT file. You can then insert this file into a Container field using the File... menu item from the Insert menu. Make sure to insert the .ZIP or .SIT file with the "store only a reference to the file" not selected.

After you have the folder inserted into a global Container field, you can create the following script:

Set Variable [$Path; Value: "file:" & Get(FileMakerPath) & MYTABLE::xfolder_container]
Export Field Contents [MYTABLE::xfolder_container; "$Path"; Automatically open]
Pause/Resume Script [Duration (seconds): 2]
Commit Records/Requests [Skip data entry validation; No dialog]
Export Field Contents ["$Path"]

The Set Variable script step specifies a local variable as the path for the following Export Field Contents script steps. The formula uses the Get(FileMakerPath) function to place the zipped or stuffed folder into the FileMaker Application folder but you can use any path to specify a path on the local hard drive:

Get(DesktopPath)
Get(DocumentsPath)
Get(FilePath)
Get(PreferencesPath)
Get(FileMakerPath)
Get(TemporaryPath)

Make sure to precede the path returned by the functions above with "file:" to complete the path requirements for a file. The name of the path is provided by the name of the compressed folder stored in the global Container field. When you store files in a Container field without selecting the reference option, FileMaker Pro returns the name of the file as the text result of a calculation formula. If you use a referenced file in a calculation, it returns the path to the file. Be careful when using the Get(FilePath) function because it returns the path to the file on the server if the file is being hosted.

The first Export Field Contents script step exports the contents of the global Container field to the path specified in the variable. The option to automatically open the exported file is selected so the .ZIP or .SIT file is decompressed. Before you run this script, you must make sure to set up .ZIP and .SIT files to open with Stuffit Expander so they automatically decompress without any dialogs. You can do so on a Macintosh using Get Info on any .ZIP or .SIT file and setting the "Open With" option to Stuffit Expander. Make sure to also click on Change All to apply the settings to all .SIT and .ZIP files. I don't believe Windows has a corresponding option to decompress files without dialogs so this technique is Macintosh-only.

At this point, the script pauses for two seconds so the folder has time to decompress. After the pause, the script commits the record so no fields are selected. This step is important for the last Export Field Contents script step which exports without a target field. If a field happens to be selected, the contents of that field would be exported. In this case, no target field should be specified or selected for the .ZIP or .SIT file to be deleted.

This basic version of the script works great but doesn't track whether the folder exists already. To prevent the existing folder and its contents from being deleted, you must add some scripting code:

Set Error Capture [On]
Set Variable [$Path; Value: "file:" & Get(FileMakerPath) & Left(GetAsText(MYTABLE::xfolder); Length(GetAsText(MYTABLE::xfolder_container)) - 4) & "/"]
Import Records [No dialog; $Path; Picture and movie files]
If [Get(LastError) = 100]
   #Place existing script code here!
Else
   Show Custom Dialog ["Folder Already Exists"; "The folder already exists in the FileMaker Application directory."]
End If

My good friend Jeff Cohen showed me this technique and we worked together to streamline the error-checking process. The problem was how to check for an existing folder with the same name. Jeff had already come up with the idea of placing a text file in the folder. If the file existed, you knew the folder existed. I started thinking, "what feature in FileMaker Pro works with folders so I don't have to use a file to check whether the folder exists?" The feature I came up with was importing the contents of a folder.

To make this technique work, first turn on Set Error Capture. The next step is to set the $Path variable to the location of the folder that might (or might not) exist. You do so by removing the last four characters from the end of the .ZIP or .SIT file stored in the global Container field. With the path set correctly, the script attempts to import the contents of the folder. If the folder doesn't exist, an error 100 is returned.

Create a Folder

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    John OsborneTechnical editor John Mark Osborne is president and owner of Database Pros, offering FileMaker resources on the Internet. He is author of Scriptology, a speaker at FileMaker Developer Conferences and Macworld conferences, and a trainer for the Professional Training series created by FileMaker, Inc. http://www.databasepros.com jmo@filemakerpros.com

    Printer-friendly
    page layout

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro

    ADVISORAMA
    I went to college, majored in Philosophy. My father said, "Why don't you minor in Communications so you can wonder out loud?"
    -- Mike Dugan

    ARTICLE INFO

    FileMaker Advisor

    Web Edition: 2008 Week 15, Doc #19413

    Print Edition: April 2008, Page 59

    SUBSCRIBER ONLY ARTICLE LOCKED

    Subscribe to FileMaker Advisor Magazine

    Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

    FileMaker.Advisor.com

    Subscribe to Advisor Basics of FileMaker Pro

    Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

    FileMaker.AdvisorBasics.com

    Secrets Of The Top Experts -- Now!

    See exactly how to do it, step-by-step, in Advisor Academy CDs created by the top experts. Click to see what you can learn right now.

    AdvisorAcademy.com

    Free E-Newsletters

    Keep up! Hot News, How-To, Tips & Tricks, Expert Advice, and more. Click to request your's free.

    AdvisorUpdate.info

    Need Know-How Now?

    What direction are you going with your business? Advisor Guides are packed with the answers you need to work smarter. Can you afford to fall behind?

    AdvisorStore.com

    Showcase Your Smarts

    Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!

    AdvisorTips.com

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2008 Advisor Media, Inc. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, Inc. in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    osboj038-03 posted 04/07/2008 modified 05/12/2008 03:42:44 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 05/16/2008 12:15:51 PM