Announcement

Collapse
No announcement yet.

Dynamically rename a file?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamically rename a file?

    I need to rename a file to the exact date of when it got renamed.
    I already tried entering %Date% but that gives an error messsage ("Could not rename file. (#99, Line 5)")

    Thanks ahead

  • #2
    Re: Dynamically rename a file?

    When you grab the whole date at once, it contains forward slashes ie. 10/11/2003
    You can’t give a file a name with slashes in it. Instead, grab the year, month, and day separately and stick them back together.

    %Year% = System.GetDateTime ( "Date", "Year")
    %Month% = System.GetDateTime ( "Date", "Month")
    %Day% = System.GetDateTime ( "Date", "Day")
    %FullDate% = "%Year%%Month%%Day%"
    File.Rename ("%SrcDir%\OldFile.txt", "%SrcDir%\%FullDate%.ext")

    Here’s the code.

    <IR_ACTIONS_LIST>
    <Action name="Get Date Time">
    <Type>139</Type>
    <Function>0</Function>
    <DTIndentLevel>0</DTIndentLevel>
    <Enabled>1</Enabled>
    <ErrorHandling>
    <UserNotificationMode>2</UserNotificationMode>
    <CustomErrorMessage/>
    <OnErrorAction>0</OnErrorAction>
    <JumpToLabel/>
    </ErrorHandling>
    <Variable>%Year%</Variable>
    <ReturnType>0</ReturnType>
    <Date>6</Date>
    <Time>0</Time>
    </Action>
    <Action name="Get Date Time">
    <Type>139</Type>
    <Function>0</Function>
    <DTIndentLevel>0</DTIndentLevel>
    <Enabled>1</Enabled>
    <ErrorHandling>
    <UserNotificationMode>2</UserNotificationMode>
    <CustomErrorMessage/>
    <OnErrorAction>0</OnErrorAction>
    <JumpToLabel/>
    </ErrorHandling>
    <Variable>%Month%</Variable>
    <ReturnType>0</ReturnType>
    <Date>4</Date>
    <Time>0</Time>
    </Action>
    <Action name="Get Date Time">
    <Type>139</Type>
    <Function>0</Function>
    <DTIndentLevel>0</DTIndentLevel>
    <Enabled>1</Enabled>
    <ErrorHandling>
    <UserNotificationMode>2</UserNotificationMode>
    <CustomErrorMessage/>
    <OnErrorAction>0</OnErrorAction>
    <JumpToLabel/>
    </ErrorHandling>
    <Variable>%Day%</Variable>
    <ReturnType>0</ReturnType>
    <Date>5</Date>
    <Time>0</Time>
    </Action>
    <Action name="Set Value">
    <Type>6</Type>
    <Function>0</Function>
    <DTIndentLevel>0</DTIndentLevel>
    <Enabled>1</Enabled>
    <ErrorHandling>
    <UserNotificationMode>2</UserNotificationMode>
    <CustomErrorMessage/>
    <OnErrorAction>0</OnErrorAction>
    <JumpToLabel/>
    </ErrorHandling>
    <Variable>%FullDate%</Variable>
    <Value>%Year%%Month%%Day%</Value>
    <Evaluate>0</Evaluate>
    </Action>
    <Action name="Rename">
    <Type>30</Type>
    <Function>0</Function>
    <DTIndentLevel>0</DTIndentLevel>
    <Enabled>1</Enabled>
    <ErrorHandling>
    <UserNotificationMode>2</UserNotificationMode>
    <CustomErrorMessage/>
    <OnErrorAction>0</OnErrorAction>
    <JumpToLabel/>
    </ErrorHandling>
    <OldFileName>%SrcDir%\OldFile.txt</OldFileName>
    <NewFileName>%SrcDir%\%FullDate%.ext</NewFileName>
    </Action>
    </IR_ACTIONS_LIST>

    Comment


    • #3
      Re: Dynamically rename a file?

      Sorry, I didn’t pay attention to what forum you posted in. I thought you were using AMS. For Setup Factory it will be similar, except the variable names are.

      %CurrentDay%
      %CurrentMonth%
      %CurrentYear%

      Comment


      • #4
        Re: Dynamically rename a file?

        Well that worked fine I tried the #DATE# and %Date% variables.. when those didnt worked i stopped trying the other date-variables.. doh!

        Thanks!

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎