7 Replies Latest reply on Mar 3, 2009 12:39 PM by tps1

    How to confirm file existence?

    tps1

      Title

      How to confirm file existence?

      Post

      I have a database in which each record contains a Container field. I want to insert a file into the Container based on a name I assemble from another field (e.g., if the field contents are "abc", I want to insert "filewin://path/folder/abc.zip") I can't use Insert File (as far as I know) since it doesn't seem to allow me to specify a variable or field as the name of the file to insert.

       

      Set Field does allow me to do this. However, it doesn't seem to give an error when the desired file doesn't exist, even when I try to capture an error with Get (LastError). How can I tell whether the file was actually found and copied into the container?

       

      Also, is only a reference copied, or the file itself? (Insert File gives the option, but Set Field doesn't.)


      I'm using FM Pro Advanced 8.5 to write this script. 

       

        • 1. Re: How to confirm file existence?
          Jade
            

          This script works using FMP 9.03 (mac).  Unfortunately, I am not able to verify this with your version 8.5 (pc) but hopefully, it will help.

           

          The variable "$filename" is entered into the "specify source file" in the Insert File[] script step.

          Replace "file:filename" with your field containing your "filewin://path/folder/abc.zip" 

           

          Go to Field [yourtablename::yourfieldname]

          Set Varialbe [$filename; Value:"file:filename"]

          Set Error Capture [On]

          Insert File [Reference; "$filename"]

          If [Get(LastError) > 0]

            Show Custom Dialog ["yourTitle"; "File not found!"]

          End If

          • 2. Re: How to confirm file existence?
            tps1
              

            Thanks a lot, Jade. I'll give this a try in 8.5 and report back if it solves the problem. 

            I don't have FM on this system, but I believe the problem will be entering the Insert File script step...it doesn't seem to allow me to use a variable for the file name, but brings up a dialog and I have to specify a particular file. But I'll keep experimenting. 

            • 3. Re: How to confirm file existence?
              Jade
                

              tps1 wrote:

               but brings up a dialog and I have to specify a particular file. But I'll keep experimenting. 


              Instead of entering a particular file, enter the variable name in that dialog box:
              $filename 

               


              • 4. Re: How to confirm file existence?
                tps1
                  

                OK, now I see that you can use a variable in the Insert File step in place of an actual pathname, and that works fine as long as the file exists. That's cool.

                However, if it doesn't exist, Insert File appears to interrupt the script and bring up the Specify File dialog which requires one to specify a file or hit cancel. Is there any way to have it just ignore the missing file and go to the next step in the loop?

                • 5. Re: How to confirm file existence?
                  Jade
                    

                  tps1 wrote:

                  Is there any way to have it just ignore the missing file and go to the next step in the loop?


                  Sorry… I went through everything I could think of and came up empty.
                  Perhaps someone else can help?
                  Or take a look at third party plug-ins something like the Grab-it plug-in:
                  http://www.fmwebschool.com/grabit.php 

                   


                  • 6. Re: How to confirm file existence?
                    FentonJones
                      

                    There was a recent thread on the TechNet mailing list which showed a (couple of) method to do this, using plain FileMaker. Since that is more or less a proprietary list, and since I did not write the technique (which is a bit tricky), I don't feel I should post it here without permission. You could join TechNet ($99/year). 

                     

                    Since I'm mostly on a Mac, I've always just used AppleScript for this. I cannot tell what platform you are on. On Windows you could use the free MooPlug plug-in, or any plug-in (or command line) that lets you look at the file system.

                     

                    The Troi File plug-in will let you build the test right into a FileMaker calculation, which you can search on in real time. But it's a bit pricey for one thing like this; awesomely powerful though (the new drag-and-drop is something else; when can we have it in FileMaker :-?)

                    • 7. Re: How to confirm file existence?
                      tps1
                        

                      The MooPlug plug-in was the solution for me (FileMaker 8.5 on Windows). Among its many functions was Moo_FileExists which allowed me to check whether the file I wanted to Insert File in my script existed. The problem is that if it doesn't and you invoke Insert File, the script stops while a Specify File dialog is presented. 

                      MooPlug is free (see MooPlug.com) but I sent the developer a couple bucks via PayPal for making such a useful tool available.

                      (Incidentally, most of you FM power users certainly already know this, but to install this plug in I simply copied MooPlug.fmx to C:\Program Files\FileMaker\FileMaker Pro 8.5 Advanced\Extensions. It then shows up in Edit > Preferences > Plug-Ins.

                      Thanks for everyone who offered advice and help; I definitely saved a lot of hair pulling by asking on this forum.