1 2 Previous Next 25 Replies Latest reply on Oct 4, 2016 12:12 PM by peterbb

    checking on a file's existence

    peterbb

      Hi,

      I need to check on a file's existence, a file on a distant server. Would this be done with a script? Can someone point me to the script parameters to use for something like this? And, I want to light up a checkbox green if the file exists.

       

      Thanks,

      Peter

        • 1. Re: checking on a file's existence
          philmodjunk

          Please explain what you mean by "file on a distant server". How would you, without using FileMaker access that file? Via a web browser? A shared directory? Or ????

          • 2. Re: checking on a file's existence
            fmpdude

            Check out the free Base Elements plugin. It has a file exists function.

             

            MBS software has similar functionality.

             

            HOPE THIS HELPS.

            • 3. Re: checking on a file's existence
              peterbb

              Well, I mean just that. I'm designing this image database. I want to know whether an image exists or not in a particular directory on a distant server. It's actually a Linux server, but, it's got a SAMBA share, so, it's readily accessible from my Mac or my Windows server (when I eventually put this dB on that Windows server). I need to check whether a file exists as a print color file, which resides in one directory, or, whether it exists as a print gray file, which resides in another directory.

               

              Here's a simple file check on my Mac:

               

              pb4072aiMac:master pb4072a$ if [ -f dy4228g1 ]

              > then

              > echo 'dy4228g1 exists'

              > fi

              dy4228g1 exists

               

              So. I'm just green in FM as to how I can do something like this. See if a file's there, and then, if it is, light up a checkbox green, or put a checkmark in it, or anything like that.

              Thanks!

              Peter

              • 4. Re: checking on a file's existence
                peterbb

                Thanks. I've been pointed to those things before. I've even downloaded something. But, I have no idea how to use them. Something I read on their website implied using Pyton, and, I definitely don't want to deal with that.

                • 5. Re: checking on a file's existence
                  Malcolm

                  Over at StackExchange you'll probably find your question asked and answered in five different ways.

                  • 6. Re: checking on a file's existence
                    peterbb

                    I downloaded the FreeBase plug-ins. I put the file into my FM folder. And, amazingly, these features now show up when I go into script mode. Very cool. So, I've created two scripts, one for color print files, one for gray print files, looking into their respective paths. So,how can I get their checkboxes to put a check in if the file's there? Is that all scripting?

                    • 7. Re: checking on a file's existence
                      fmpdude

                      Yep, you just need to do something like "SET FIELD <field_Name> to checked" or whatever you named your checkbox. The only thing to figure out is what event on your form you want as the trigger.

                       

                      -----

                       

                      For example, you might have a checkbox field tied to a Value list with "Print" as its value as you see below. In code (script), if you SET FIELD <FIeld_NAME_ON_YOUR_FORM> TO "Print?" (in this case), you will "Check" the checkbox.

                       

                       

                      It's all super simple now that you have the File Exists capability working.

                       

                      Good job.

                      • 8. Re: checking on a file's existence
                        peterbb

                        Uh, sorry, but, I can't seem to get it still. Here's what I have in my script:

                         

                        BE_FileExists ( "//bpub-files-prod/graphics/artrefpdf_color/master" & Image::__pkImageID )

                        SET FIELD <Print::InPrintColor> TO "PrintColor?"

                         

                        And, it won't save with that. It says it can't see that table name. But, that's the table name. It's in the "Print" table, and it's named "InPrintColor."

                         

                        Where does the value list come in here?

                         

                        Thanks.

                        • 9. Re: checking on a file's existence
                          erolst

                          peterbb wrote:

                           

                          I downloaded the FreeBase plug-ins. I put the file into my FM folder. And, amazingly, these features now show up when I go into script mode.

                           

                          What the BaseElement plug-in provides are functions, not script steps; so you can access and use them them wherever you make use of the calculation engine.

                           

                          So, while a script-based solution is possible, a purely function-based approach might be more convenient (as it requires no trigger per se, except for a refresh, which a screen load will provide), e.g. in a non-stored calculation like:

                           

                          cPrintVersions, unstored, type text =

                           

                          List (

                            Case ( BE_FileExists ( "PathToGrayscaleVersion" ) ; "Gray" ;

                            Case ( BE_FileExists ( "PathToColorVersion" ) ; "Colour"

                          )

                           

                          Put that field on your layout and format it as a checkbox with a static value list of "Gray¶Colour", and you'll see the appropriate check for either version.

                           

                          Or use two number fields, each using simply

                           

                          BE_FileExists ( "PathToAppropriateColourVersion" )

                           

                          and format the field as a checkbox, using a value list with just the number 1.

                           

                          Alternatively, don't create any fields; just put two graphics on the layout and hide/show each using the predicate

                           

                          BE_FileExists ( "PathToAppropriateColourVersion" )

                          • 10. Re: checking on a file's existence
                            peterbb

                            Wow. This is juicy stuff. But, this is showing how green I am at FM at this point, still. Everything you typed up there, beginning with "List," definitely looks like scripting to me. You say to "put that field on your layout and format it as a checkbox...." How does one put that "List" stuff onto a layout?

                             

                            Thanks.

                            • 11. Re: checking on a file's existence
                              erolst

                              peterbb wrote:

                               

                              Uh, sorry, but, I can't seem to get it still. Here's what I have in my script:

                               

                              BE_FileExists ( "//bpub-files-prod/graphics/artrefpdf_color/master" & Image::__pkImageID )

                              SET FIELD <Print::InPrintColor> TO "PrintColor?"

                               

                              What you would need here is either

                               

                              If [ BE_FileExists ( "//bpub-files-prod/graphics/artrefpdf_color/master" & Image::__pkImageID ) ]

                                Set Field [ target field: Print::InPrintColor ; calculated result: "PrintColor?" ]

                              Else

                                Set Field [ target field: Print::InPrintColor ; calculated result: "" ]

                              End If

                               

                              or, quite a bit simpler:

                               

                              Set Field [ target field: Print::InPrintColor ; calculated result: Case ( BE_FileExists ( "//bpub-files-prod/graphics/artrefpdf_color/master" & Image::__pkImageID ) ; "PrintColor?" )

                               

                              But read my earlier reply about not using a script.

                               

                              peterbb wrote:

                              Where does the value list come in here?

                               

                              A value list is just a formatting tool that checks whether the field value(s) has (a) match(es) in the VL; so the idea is to set the field to a value that is (in) the VL so that the formatting is applied

                              • 12. Re: checking on a file's existence
                                erolst

                                "Scripting" in FM comes in two flavours; writing "actions" scripts (macros, if you like), that perform some action on the database, and writing calculation scripts that "only" return a data result.

                                 

                                And as you will see, "script scripting" uses calculations to make decisions (e.g. in Ifs, Loops and the like) and to write results into fields or variables.

                                 

                                In this case, though, you only need calculations; as to whereto put that "List stuff" ;-) : You put it into a (calc) field that will return the correct result, which in turn will format the checkbox.

                                 

                                So, for the first suggested approach:

                                 

                                • Create a calculation field, type text; go to the storage tab and set it to unstored!

                                • Put in the above calc, using your actual file paths as the parameters to the two occurrences of BE_FileExists().

                                • Create a value list with "custom values", putting in the two values "Gray" and "Colour" – or whatever you want, but these two values must match the two results you specify in the field calculation.

                                • Put the field on the layout.

                                • Switch to Layout mode and select the field; in the Inspector's Data tab, select the control style "Checkbox set" and select/attach the new value list.

                                • 13. Re: checking on a file's existence
                                  peterbb

                                  erolst wrote:

                                   

                                            "Create a calculation field, type text; go to the storage tab and set it to unstored!"

                                   

                                  Sorry, but, how can a calculation field have a type of "text?" It's a type itself for a field, isn't it? And, it's a "calculation" type. Under Storage, I don't see any "unstored." Do you mean simply not to check the global storage box at the top here?

                                   

                                   

                                  I'm feeling dumb here.

                                  • 14. Re: checking on a file's existence
                                    erolst

                                    Well, "text" is not the field type, but the type of the data you wish to return.

                                     

                                    So first, create a new calculation field:

                                    Screen Shot 2016-10-04 at 17.05.36.png

                                     

                                    Now, note the open popup; this is where you set the "return data type" of a calculation field:

                                    Screen Shot 2016-10-04 at 17.00.56.png

                                     

                                    Also, the Storage tab screenshot you showed didn't come from a calculation field; this is how it would look like. Note the check on "Do not store calculation results …":

                                    Screen Shot 2016-10-04 at 17.01.18.png

                                    1 2 Previous Next