4 Replies Latest reply on Jun 20, 2017 9:34 AM by rouelf

    Pulling folder, filename from a string

    tlmurray

      Consider a path and filename, where the filename might have more than just one period; in other words, something like

              video-2016.10.23.mp4

       

      I would like to develop two calculation fields, one to pick up the filename and one to pick up the last folder in the path. So for

              whatever/somepath/A_Folder/video-2016.10.23.mp4

      one calculation is video-2016.10.23.mp4 and the other calculation is A_Folder. I can do this in a spreadsheet but can't figure it out in FileMaker. Any ideas?

        • 1. Re: Pulling folder, filename from a string
          wimdecorte

          $the_list = substitute( input_string ; "/" ; "¶" )

           

          will give you a return delimited list.

           

          $file_name = GetValue( $the_list ; valuecount( $the_list ))

           

          will give you the full file name

           

          $folder = substitute( input_string ; "/" & $file_name ; "" )

           

          will give you the folder path (or you can reconstruct it from the values in $the_list if there is a chance that the folder name will contain the same string as the file name

          • 2. Re: Pulling folder, filename from a string
            erolst

            One way:

             

            Let ( [

              stringAsList = Substitute ( YourPathString ; "/" ; ¶ ) ;

              vc= ValueCount ( stringAsList ) ;

              theFileName = GetValue ( stringAsList ; vc ) ;

              theEnclosingFolder = GetValue ( stringAsList ; vc - 1 )

              ] ;

              theFileName // or theEnclosingFolder

            )

            • 3. Re: Pulling folder, filename from a string
              hhenle

              You may want to check out the path functions of the MBS plugin. You will find all you need there.

              • 4. Re: Pulling folder, filename from a string
                rouelf

                There are various ways. I use: See attached File:

                For the Folder Name:

                Let (

                [

                Tag = "/";

                count = PatternCount ( $FilePath ; Tag ) ;

                start = Position ( $FilePath; Tag ; 1 ; count - 1 ) + 1 ;

                end = Position ( $FilePath ; Tag ; start ; count )

                ];

                If ( PatternCount ( $FilePath; Tag ) ;

                Middle ( $FilePath; start ; end - start ) ;

                "")

                )

                 

                For the File Name:

                Let (

                [

                Tag = "/";

                count = PatternCount ( $FilePath ; Tag ) ;

                start = Position ( $FilePath ; Tag ; 1 ; count )+1 ;

                end = Length ( $FilePath )

                ];

                If ( PatternCount ( $FilePath; Tag ) ;

                Middle ( $FilePath; start ; end - start ) ;

                "")

                )