Jump to content

Use of variables as a file name for record import?

This topic is 6469 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I am trying to build a script, that would allow the user to import multiple records at once.

I have a field, where the user enters the file names, that should be imported. All files have the same format, the same import order and would be in the same folder. My problem is, that FM ScriptMaker does not allow me to put a field of the database in the import records function to specify the data source. Is there a way to do that?

Any help highly appreciated.


FileMaker Version: Dev 7

Platform: Mac OS X Panther

Link to comment
Share on other sites

  • 3 weeks later...

I consider it a lousy work-around, but this is what I have done. It only works for the case where you can pre-define a list of available files. I have not been able to figure a way to have users add files to the list.

Create file references for each file.

Create a text field with the name of the file reference.

In a script use:

If [ textfield = "filename' ]

Open File [ "filename" ]

Spelling has to be exact, so consider limiting the text field to a pop-up list.

Link to comment
Share on other sites

Another way is to use either AppleScript or a plug-in, such as Troi File plug-in, to list the files in the folder, then, in a loop, rename each to a fixed name, import it, then rename it back to the original name.

Both tools above have a "list folder" command, producing a return-delimited list of the file names, which you can put in a global field. Then, using FileMaker, you can loop through and process one file at a time.

You do have to know where the folder is, but this can be calculated relative to the database file, using Status(CurrentFilePath), or Get ( FilePath) in 7, minus Status(CurrentFileName), plus the relative path to the folder & fixed file name.

There are various ways to calculate the current folder path. Here's my Mac one for v.6:

Substitute(Substitute(Left(Status(CurrentFilePath), Position(Status(CurrentFilePath), "/", 1, PatternCount(Status(CurrentFilePath), "/"))), "/", ":"),

"file:???:", "")

Similar for 7, one less ":" in "file::"

Substitute(Substitute(Left(Get(FilePath); Position(Get(FilePath); "/"; 1; PatternCount(Get(FilePath); "/"))); "/"; ":");

"file::"; "")

The advantage of this name switching method is that you don't need to know the names of the files in the folder, or how many there are. Both AppleScript and Troi File can easily rename a file very fast.

Link to comment
Share on other sites

A variation on Fenton's technique is to do nothing to the original files. Create a single import script that imports a file from a fixed location and fixed file name; maybe importme.txt.

The loop that Fenton describes is modified to one at a time, create an alias to each of your source files, name the alias importme.txt and put the alias in the known location, and perform the import, then repeat.

Link to comment
Share on other sites

This topic is 6469 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.