5 Replies Latest reply on Aug 12, 2009 6:16 PM by CountryBoy1

    Parsing for Backslash

    CountryBoy1

      Title

      Parsing for Backslash

      Post

      Trying to parse Get(FilePath) to get the lowest Folder name in the path.

      Can't get PatternCount or Position functions to work.  Am using

      "\\" as the search.  Have seen a previous answer for backslash

      parsing and it also uses "\\" but I always get 0 as answer.  Am using
      Filemaker Pro 9 advanced.  Thanks for your help.  CountryBoy1

       

        • 1. Re: Parsing for Backslash
          philmodjunk
            

          Position (text field; "\\", 1, 1)

           

          will find the first backslash in text field. (I just checked to be sure it'd work.)

           

          Post some details and we'll see where it's not working for you.

          • 2. Re: Parsing for Backslash
            philmodjunk
              

            Set Variable [$i ; 1]

            Loop

              exit loop if [Position (text field; "\\", 1, $i) = 0]

              Set Variable [$i ; $i + 1]

            End loop

            If [Position (text field; "\\", 1, $i-1) > 0 ]

              Set Variable [$LowestFolder; Right ( text field ; Length (text field ) - Position (text field; "\\", 1, $i-1) )

            Else

              #no backslashes

            End if

             

            This works if the lowest level folder in the path does not have a '\' to the right of it. IF it does, you'll need to adjust the script accordingly.

            • 3. Re: Parsing for Backslash
              comment_1
                

              CountryBoy1 wrote:

              Trying to parse Get(FilePath) ...  using "\\" as the search...  but I always get 0 as answer.


              That is the correct answer. The result of Get(FilePath) does not contain any backslash characters. To get the name of the current file's enclosing folder, try:

               

               

              Let ( [ path = Get ( FilePath ) ; len = Length ( path ) ; s = Position ( path ; "/" ; len ; -2 ) ; e = Position ( path ; "/" ; len ; -1 ) ] ; Middle ( path ; s + 1 ; e - s - 1 ) )

               


               


              • 4. Re: Parsing for Backslash
                CountryBoy1
                  

                Dear PhilModJunk:

                        Thanks for your usual good help.  However in this case I discovered

                  that Filemaker Pro 9 advanced is converting the normal Windows "\" backslash

                  in Get(FilePath) return to forward slash "/" which I believe is Unix format.

                  I should have been looking for "/". Has Filemaker always converted this

                  way or is it more recent ?  Always appreciate your help.  CountryBoy1

                 

                • 5. Re: Parsing for Backslash
                  CountryBoy1
                    

                  Dear PhilModJunk:

                      Here's the code that gets me the lowest Folder name in a file path.  It uses

                  another field, FolderName which is TrimAll( Get(FilePath) ; 1, 3) which takes all spaces

                  out of the long file path. Incidently my filepath was about 80 characters long.  I am

                  using Windows XP Professional.  (Hope that Vista works the same because my program

                  is going on a Vista machine.)

                   

                  CODE:

                  Middle (FolderName ; Position( FolderName ;  "/" ; Length ( FolderName ) ; -2) +1 ;

                  Position( FolderName ;  "/" ; Length ( FolderName ) ; -1) - Position( FolderName ;

                    "/" ; Length ( FolderName ) ; -2) -1)

                   

                  Sincerely, CountryBoy1