2 Replies Latest reply on Apr 13, 2012 1:53 PM by josh_chunick

    FileIO question

    MAC800 Level 1

      From http://www.deansdirectortutorials.com/

       

      To create a file use the following code

       

      In the message window type:

      createFile (scribe, "Multimedia.txt")

       

      What if you want the file to be created to have the date and time as part of the file name

       

      Such as tFile201204111157am.txt

       

      So my question is how do you put the current date and time as part of the file name

       

      Thanks!

        • 1. Re: FileIO question
          Mister MUX Level 2

          There might be a much more simple solution, but this should work. Also there might be system settings on the local machine that cause this to break, I am not sure.

           

          Your question isn't really a fileIO quetion, it is more of a string manipulation question. There are date and time functions and a couple of "chunk":expression concepts (itemDelimiter and item) that can be used to produce the string you want. Look them up in the online help for more info.

           

          Here is a  script the should return the string in the format you are wanting. Put it in any movie script cast member.

           

          ------------------------------------------------------------------------------------------ ---------

          on getDateTime

            saveItemDelimiter = the itemDelimiter

            the itemDelimiter = "/"

            theDate = the short Date

            DateAndTime = theDate.item[3]

            if theDate.item[1].char.count = 1 then DateAndTime = DateAndTime & "0"

            DateAndTime = DateAndTime & theDate.item[1]

            if theDate.item[2].char.count = 1 then DateAndTime = DateAndTime & "0"

            DateAndTime = DateAndTime & theDate.item[2]

            the itemDelimiter = ":"

            theTime = the short Time

            if theTime.item[1].char.count = 1 then DateAndTime = DateAndTime & "0"

            DateAndTime = DateAndTime & theTime.item[1]

            theTime = theTime.item[2]

            the itemDelimiter = " "

            if theTime.item[1].char.count = 1 then DateAndTime = DateAndTime & "0"

            DateAndTime = DateAndTime & theTime.item[1] & theTime.item[2]

            the itemDelimiter = saveItemDelimiter

            return DateAndTime

          end

          ------------------------------------------------------------------------------------------ ---------

           

           

          You can test it by typing into the message window then press ENTER

               put getDateTime()

          which should return

               -- "201204110236PM"

           

          So now you can do this

           

          createFile (scribe, "Multimedia" & getDateTime() & ".txt")

          • 2. Re: FileIO question
            josh_chunick Level 1

            I wouldn't use the shortDate or the shortTime as they are most certainly affected by the user's OS date and time formatting. I would instead use the systemDate which returns something like this:

             

            d = date( 2012, 4, 13 )

             

            from which you can extract the date and time like this:

             

            year = string(d.year)

            month = string(d.month)

            if month.length = 1 then month = "0" & month

            day = string(d.day)

            if day.length = 1 then day = "0" & day

            hours = string(d.seconds / 3600)   -- this will return value between 0 and 23

            timeDay = AM

            if hours > 11 then timeDay = PM

            if hours > 12 then hours = hours - 12

            hours = string(hours)

            if hours.length = 1 then hours = "0" & hours

            minutes = string((d.seconds mod 3600) / 60)

            if minutes.length = 1 then minutes = "0" & minutes

             

            so then you would do this:

            fileName = year & month & day & hours & minutes & timeDay & ".txt"


            if you need seconds:

            seconds = d.seconds mod 60

            Mister MUX wrote:

             

            There might be a much more simple solution, but this should work. Also there might be system settings on the local machine that cause this to break, I am not sure.

             

            Your question isn't really a fileIO quetion, it is more of a string manipulation question. There are date and time functions and a couple of "chunk":expression concepts (itemDelimiter and item) that can be used to produce the string you want. Look them up in the online help for more info.

             

            Here is a  script the should return the string in the format you are wanting. Put it in any movie script cast member.

             

            ---------------------------------------------------------------------- -----------------------------

            on getDateTime

              saveItemDelimiter = the itemDelimiter

              the itemDelimiter = "/"

              theDate = the short Date

              DateAndTime = theDate.item[3]

              if theDate.item[1].char.count = 1 then DateAndTime = DateAndTime & "0"

              DateAndTime = DateAndTime & theDate.item[1]

              if theDate.item[2].char.count = 1 then DateAndTime = DateAndTime & "0"

              DateAndTime = DateAndTime & theDate.item[2]

              the itemDelimiter = ":"

              theTime = the short Time

              if theTime.item[1].char.count = 1 then DateAndTime = DateAndTime & "0"

              DateAndTime = DateAndTime & theTime.item[1]

              theTime = theTime.item[2]

              the itemDelimiter = " "

              if theTime.item[1].char.count = 1 then DateAndTime = DateAndTime & "0"

              DateAndTime = DateAndTime & theTime.item[1] & theTime.item[2]

              the itemDelimiter = saveItemDelimiter

              return DateAndTime

            end

            ---------------------------------------------------------------------- -----------------------------

             

             

            You can test it by typing into the message window then press ENTER

                 put getDateTime()

            which should return

                 -- "201204110236PM"

             

            So now you can do this

             

            createFile (scribe, "Multimedia" & getDateTime() & ".txt")