10 Replies Latest reply on Oct 27, 2015 6:51 AM by rtolliver

    Parsing Text: Pathname

    rtolliver

      Title

      Parsing Text: Pathname

      Post

      Is it possible to create a pathname for a container field by Parsing and concatenation?  I have a table of records that contain text fields that are the pathname for pictures on an external drive. 

      (PC) Old Pathname - \\De07-HP\UniqueDB\Wood\syc\syc0062-a.jpg 

      (Mac) New Pathname - Mac07:/UniqueDB/Wood/syc/syc0062-a.jpg 

      I'm attempting to write a script to Parse the old pathname, removing the computer name and then concatenate it with the new computer name.

        • 1. Re: Parsing Text: Pathname
          philmodjunk

          If you mean that you want to modify the current path name inside a container field, then yes, you can do this with either set field (to change it in one record) or Replace Field Contents (to update the path in all records of a found set).

          The trick is first to figure out exactly what format and path details are needed, then figure out a calculation that does the needed "surgery" on the existing path and then you set up one of these script steps to modify the container field just as though it is a text field.

          • 2. Re: Parsing Text: Pathname
            rtolliver

            The container fields are currently empty, they have no picture so there is no pathname. These fields were added to the table after data was imported. Each of the records imported has 2 text fields that are pathnames that I need to convert to the new name.

            I've used FilePathExtractor to identify the correct pathname so all I need now is to modify each record's old pathname. Once the old pathname is changed I intend to use it as a script variable to insert pictures into the container fields.

            • 3. Re: Parsing Text: Pathname
              philmodjunk

              Ok, so it's the actual text parsing that's the issue.

              Left ( YourPathFieldHere ; Position ( YourPathFieldHere ; "\\" ; 1 ; 3 ) - 1 )

              Should return all text to the left of the 3rd \ in the field.

              Let ( [ Pth = YourPathFieldHere ;
                         L = Length ( Pth )
                        ] ;
                          Right ( Pth ; L - Position ( Pth ; "\\" ; 1 ; 3 ) )
                      ) // Let

              Should return all text to the right of the third \ if I haven't introduced a mistake here.

              Note: Inside quoted text, the \, is the escape character. When a quoted string is evaluated, FileMaker removes the \ and treats the following character as just another character in the string. This is used to insert the quote character into a quoted string without it being interpreted as the operator marking the end of a quoted string.

              "quoted text here: \"This is in quotes\" This is not in quotes"

              will evaluate as:

              quoted text here: "This is in quotes" This is not in quotes

              So to get a \ to be treated as the actual \ character you have to "escape the escape character" by doubling it. That's why you see "\\" inside the position function call. It's really checking for the position of a single \ character.

              If any of these functions are not familiar, please look them up in help before asking about them.

              • 4. Re: Parsing Text: Pathname
                rtolliver

                Thanks a lot for the example.

                • 5. Re: Parsing Text: Pathname
                  rtolliver

                  With your example I created a script that produces a pathname, see attached. I have to apologize for not including this new question with the original post, because FM is cross platform I didn't know if "Backslash and Forward Slash mattered in a pathname. Are there script steps and or functions that can find and replace the Backslash with a Forward slash?

                  • 6. Re: Parsing Text: Pathname
                    philmodjunk

                    The substitute function can replace one character with another.

                    • 7. Re: Parsing Text: Pathname
                      rtolliver

                      I've tested the substitute function and got the error dialog in the attached screen shot.  According to FM Help, operators are looked at as text when placed inside double quotation marks, if this is true what else is required to prevent the error? 

                      Substitute ( GLOBALS::xPathname ; "\" ; "/" ) 

                      xPathname = UniqueDB\Wood\pop\pop0001-b.jpg

                      • 8. Re: Parsing Text: Pathname
                        philmodjunk

                        Use Substitute ( Globals::xpathname ; "\\" ; "/" )

                        \ is the "escape character, the one operator that IS evaluated inside a quoted string. It tells FileMaker to treat the following character as a text and not an operator. This is typically used to put double quotes as characters inside a quoted string such as:

                        "This text is not quoted. \"This text IS quoted\" see?"

                        So when you want \ to be treated as the actual character and  not the escaped character, you have to escape the escape character. Inside quoted text \\ evaluates as the single \ character.

                        • 9. Re: Parsing Text: Pathname
                          rtolliver

                          Phil,

                          thank you very much for your help and especially your patiences, I was not seeing the forest for the trees.

                          • 10. Re: Parsing Text: Pathname
                            rtolliver

                            I created a script based on your input and it ran fine. I tried running it again yesterday on a test database and got an error message "The file "$NPath2" could not be found and is required to complete this operation". I haven't made any changes to this script sense running it the first time.

                             

                            I've looked a the set variable $NPath2 and I don't see any problems unless the name "Pth" should be changed.  I was hoping you could take a look.

                            Path Test2.jpg