5 Replies Latest reply on Oct 23, 2012 11:32 AM by philmodjunk

    Importing filename to field?

    SandyHaaf

      Title

      Importing filename to field?

      Post


           Is there a way to import the filename of a .csv file as a field during an import? 

           I've asked my techies to add a field to the file that will identify which device the data is from.  And they said that they won't do it b/c it is bad programming and will add space.  They want me to pull the information for the device from the filename.  I can't see anyway to do this.

           Is is possible?  

           Thanks,

           Sandy

        • 1. Re: Importing filename to field?
          philmodjunk

               hey won't do it b/c it is bad programming and will add space.

               Hmmm we have hard drives measured in Tera Bytes, Ram meaured in GigaBytes and adding the few extra bytes needed for the file name creates a problem by 'adding space'? !!

               Here's a couple of approaches that should enable you to capture a file name:

               Option 1:

               Use a script that first inserts a refrence to the file to be imported into a container field. This can be set up so the user gets an open file dialog where they select the csv file. The script then extracts the file name from the container field and can use set field to put it in a field in yourdatabase. It also can take the file name and path from the container field, put it in a variable and then the next step in your script uses Import records with a reference to the variable to import the records.

               From the user's perspective, they click a button, select the file in the open file dialog box and then the script imports the data and captures the file name.

               Option 2:

               get a plug in for FileMaker. There are several plug ins available that can read the contents of the directory to list the file names contained in it. Such a plug in should be able to acquire the file name of your csv file so that you can store it in your database.

          • 2. Re: Importing filename to field?
            SandyHaaf

                 So, I've made some progress on option 1.  I have imported the file to the container field.  I have extracted the path/filename to a field (path) and extracted just the filename to field (file name).

                 But, I am having trouble with the Import Records in my script.  I can't figure out how to tell it to use the file from the field path instead of me hardcoding or having the user reselect the file.

                 How do you get Import Records to accept the path from a field?

                  

                 I've attached pic of my script so far.

                  

                 Thanks,

                 Sandy

            • 3. Re: Importing filename to field?
              philmodjunk

                   You put the filepath into a variable, not a field.

                   I use:

                   Set Variable [$Path ; GetValue ( Import file::container ; 2 ) ]

                   Note that this skips a few steps that you are using to get to this text.

                   Then, I open the specify File dialog by selecting File from the drop down and type in $Path as the first row of text in this dialog. I keep the "hard coded" file path as the second line of text as this preserves any import options, such as field options that I may have specified for this script step.

              • 4. Re: Importing filename to field?
                SandyHaaf

                     The variables worked and your way was much simpler using GetValue thanks!

                      I'm getting so close - I still have 2 issues I need to figure out for my script to be complete.

                     1.   I need to set the Input Data::Turbine Id  to be the value in Input File::File Name  (this table only has one record with appropriate information) for all records in Input Data.    This sounds simple but I can't figure it out.

                      

                     2.  I need to copy all the records in Input Data into our Wind Data table  (this is the permanent location). 

                     Thanks,

                     Sandy

                      

                     Now I need to find out how to 'copy' all the records from one table to a different permanent table. 

                      

                     Thanks,

                     Sandy

                • 5. Re: Importing filename to field?
                  philmodjunk

                       1)

                       Set Variable [ $Fname ; value: Input File::File Name ]
                       Go to layout ["Input Data" ( Input Data ) ]
                       Set Field [Input Data::Turbine Id ; $Fname ]

                       2)

                       This can be another case of using Import Records. Import Records is not limited to moving data from a table in one file to  to a table in another file, you can use it to move data from one table to another in the same file. You just select the file you already have open just as  though it was a separate file.