4 Replies Latest reply on Jul 18, 2011 3:29 PM by philmodjunk

    Import file and make a copy in folder



      Import file and make a copy in folder


      Hi all,

      I'm looking for a way to copy and move files which are not in the Filemaker database, but using scrips in Filmaker to do that.

      I'll try to explain:

      * One table of my database is dedicated to store files (.pdf ; .docx; .txt) linked to our daily work.

      * At the moment, I import all files to the database using "Save only a reference". We have dedicated a folder on our internal server and all files added to the database have to be moved first to this folder manually through Windows Explorer before we can import them to the "Container" field in the database.

      * This system works but is very limited, because it happens that the files get moved or deleted by users on the server.

      My question: Is there a script that opens the import file dialog box, the user selects the file he wants to import to the database and Filemaker makes automatically a copy of this file in a designated folder using a field "ID" as name for the file and store only a reference to this file in the database.

      Thank you for your help

        • 1. Re: Import file and make a copy in folder

          You can use Export Field Contents to export the file to a location you specify (put file name and file path in a variable).

          Then Use insert file to re-insert the file from the new location and you will have moved your file. (Use the same variable as it has the filepath and file name you need.)

          You can even use export field contents with a path to the original file, but with no field specified to delete the original, but that is an option to use with care so that a mistake does not delete the wrong file.

          • 2. Re: Import file and make a copy in folder

            Thank you, works perfect !

            • 3. Re: Import file and make a copy in folder

              Hi PhilModJunk,

              The script works perfect on Mac, but now that I transferred the FMP file on Windows I'm not able to open the re-imported file saved as a reference by double clicking on the container field. Somehow it seems that the Mac recognizes the file type and opens it correctly and not Windows.

              Here is my script:

              Set Error Capture [On]

              Insert File [HistoricNotes::Attachments]

              Set Variable [$FileName; Value:Historic::HistoricID]

              Export Field Contents [HistoricNotes::Attachments, "$FileName"]

              Insert File [Reference; HistoricNotes::Attachments; "$FileName]

              Is there a way to get the file extension of the original file, set it in a variable and add it to the exported FileName?

              • 4. Re: Import file and make a copy in folder

                It's not the script, but rather that the filepath to the file is different on your two platforms.

                The image must be stored in a shared directory directly accessible from both machines, but the two systems format the same file path differently.

                Try this out to see what I mean.

                Define a calculatton field and set it to return text.

                Enter the name of your container field as the sole item in its calculation.

                Put this field next to your container field on your layout and size it to be 4-5 lines to text tall. You may need to click into it or give it a scroll bar to seen the entire text.

                Now insert a file by reference into the container field and note what text is stored. Do this on both machines.

                In order for both to see the image, you need either an indentical path to the image file or a calculation field that identifies the operating system of the current user and returns the correct file path for that platform. Either that or you use a web viewer to display the image file with a URL calculation that uses the same methods to produce the appropriate file path.