Renaming file with current date and time

I would like to rename a file with the current name it already has with the current date and time at the end of the file name - how would I go about doing this?

Hi @E.T.S

You could use the following approach:

nowData = Now.ToString("yyyyMMddHHmmss")

Then renaming the file like:

updatedFileName = Path.GetFileNameWithoutExtension(filePath) + "_" + nowData.ToString + Path.GetExtension(filePath)

Hope this helps,
Best Regards.

Hi thanks for you reply!

For the nowData variable which variable type would that be please :slight_smile:


nowData variable be of the data type ‘String’.

Best Regards.

I am not sure how to edit the code with a move file/folder activity - I have replaced filepath with item and am getting the following error:

Can you please share the input and output file names

I won’t know the file names prior to them being uploaded to SharePoint unfortunately - would that hinder adding the date and timestamp to the existing file name


you can try

oldfilename= Path.GetFileNameWithoutExtension(filePath)


When I edited the code to this:

I get this error message:

I think the issue is because the file name is a drive item?


its better to use rename file activity

and then use move file activity

hope this helps




can you check the value of item.tostring by placing a log message above of rename file activity and whether the file name is coming or not

The name isn’t coming out


The log message for the above is:


you can rename a file by adding the current date and time to its current name using a combination of activities. Here’s a step-by-step guide:

  1. Assign Activity (Optional): If you want to store the current date and time in a variable, you can use an “Assign” activity. Create a variable (e.g., currentDateTime) of type DateTime and assign it the current date and time using the Now function.

  2. Get File Properties Activity (Optional): If you want to work with an existing file, you can use the “Get File Properties” activity to retrieve information about the file. This can be useful if you need to get the file’s current name.

  3. Rename File Activity: Use the “Rename File” activity to rename the file. Set the “OldFileName” property to the current file’s path and filename, and set the “NewFileName” property to the desired new name, including the current date and time. You can concatenate the currentDateTime variable or use UiPath’s built-in date and time functions to format the date and time as needed.

Here’s a simple example using UiPath Studio:

        - currentDateTime (type: DateTime)
        - Assign: Assign currentDateTime = Now
        - Get File Properties (Optional): Set File path
        - Rename File:
            - OldFileName: "C:\Path\To\Your\File.txt" (or use the result from Get File Properties)
            - NewFileName: "C:\Path\To\Your\File_" + currentDateTime.ToString("yyyyMMddHHmmss") + ".txt"

In this example, replace "C:\Path\To\Your\File.txt" with the actual path to your file. The ToString function is used to format the currentDateTime variable as “yyyyMMddHHmmss,” which is commonly used for including a date and time in filenames.


check this

hope this helps

How would I configure the above for a drive item

Is there a way of getting the file name of the drive item

Would this work with a drive item?

Is there a way of getting the file name of the drive item

Managed to solve it by using and adding it to the NowData - thanks everyone!

1 Like