1 Reply Latest reply on Feb 4, 2010 11:05 PM by furbies

    Substitute Script Step in Runtime Solution

    furbies

      Title

      Substitute Script Step in Runtime Solution

      Post

      Hi All

       

      I'm writing a script that is to go into a FM 9.0.3 Runtime (I have FM 9.0.3 Advanced, Mac OS 10.6.2) and in the script I have the following code:

       

      Insert File [ Books::gTempTextContainer ] [ Reference ]

       

      Set Variable [ $fileName; Value:Substitute ( GetValue ( Books::gTempTextContainer ; 1 ) ; "file:" ; "" )

       

      The problem is that when I run the script from within FM Advanced, $fileName ends up being the name of the actual file selected in Insert File, but when I run the same code from within a Runtime Solution, $fileName seems to still be the whole file path not just the fileName.

       

      Is there some limitation ? I can't find any references that point me in the right direction?

       

      tia

       

      furbies 

        • 1. Re: Substitute Script Step in Runtime Solution
          furbies
            

          I discovered what I was doing wrong. Doh!

           

          In FM Adv, Insert File returns file:<nameOfFile> as the first line, but in a Runtime Insert File returns a whole path & filename.

           

          This is the code I came up with to get around the problem in the Runtime

           

          # Get the file of interest 

          Insert File [ Books::gFilePathContainer ] [ Reference ]

           

          # Get the file path & file name

          Get the full file path from the second line in Books::gFilePathContainer & remove the leading filemac:/ 

          Set Variable [ $filePath; Value:Substitute ( GetValue ( Books::gFilePathContainer ; 2 ) ; "filemac:/" ; "" )]

           

          Find the last "/" in the file path so we can then extract the file name from the end of the file path 

          Set Variable [ $lastPos; Value:Position ( $filePath ; "/" ; Length ( $filePath ) -1; -1 ) ]

           

          Get the name of the file from the end of the file path  

          Set Variable [ $fileName; Value:Middle ( $filepath ; $lastPos + 1 ; 64000 )]

           

          # Remove the file name from the end of the file path  

          Set Variable [ $filePath; Value:Left ( $filepath; $lastPos )]