3 Replies Latest reply on Apr 17, 2015 10:38 PM by christopherc

    Get extension of file in container field with script

    MrBond

      Title

      Get extension of file in container field with script

      Post

      How can I determine the extension of a file stored in a container field with a script and pass the result to a variable? Wanna pop up a dynamic message if the user clicks a button and the container field is a pdf, a docx or a rtf file. Thanks!

        • 1. Re: Get extension of file in container field with script
          philmodjunk

          The following calculation will extract the complete file name from any container field regardless of storage options and insertion method except for the one deprecated option mentioned:

          //This should work for all insertion and storage methods except Insert Object (Filemaker 11, WIndows only):
          Let ( [ T = If ( LeftWords ( YourTable::ContainerFIeld ; 1 ) = "remote" ; GetValue( YourTable::ContainerFIeld ; 1 ) ; GetValue ( YourTable::ContainerFIeld ; ValueCount ( YourTable::ContainerFIeld ) ) ) ;
                    L = Length ( T )];
                    If ( LeftWords ( T ; 1 ) = "remote" ;  Right ( T ; L - 7 ) ; Right ( T ; L - Position ( T ; "/" ; L ; -1 ) ) )
              )

          So if you used this expression:

          Let ( fn = put result of above calc here ;
                  Right ( fn ; length ( fn ) - Position ( fn ; "." ; Length ( fn ) ; -1 ) )
                ) // Let

          You'd extract just the file extension from the file name of the inserted file.

          For more on this, see: Exploring the use of a $Path Variable in Scripts

          1 of 1 people found this helpful
          • 2. Re: Get extension of file in container field with script
            MrBond

            Thank you very much, I'll go for it.

            • 3. Re: Get extension of file in container field with script
              christopherc

              I also needed to get the file extension from  a file in a container field. First I got the name of the file in the container, Then I substituted periods in the name with paragraph marks (¶)  and used GetValue to extract the last value, which would be the extension.

              Set Variable [ $New Doc; Value:GetAsText(Table::Container)

              Set Variable [ $doc type; Value:Let (name = Substitute($New Doc; "." ; ¶); GetValue(name;ValueCount(name)))]

              All my container files are on a local machine so while this solution has its limits, it did work for what I needed.