File rename according to the date

Guys,
Just a quick question.
Is there a way, how to set Move File activity, to move and rename the file according to current date ?
May something like this be used in the output ? (“{0:yyyy/MM/dd}”, DateTime.Now)
Thank you in advance.

  • Destination - The destination path where the file is to be moved.

Please enter the full path including file name in the Destination.

strnewFileName = "file_" + DateTime.Now.ToString("yyyyMMdd") + ".doc"

https://activities.uipath.com/docs/move-file

2 Likes

Thank you for your quick response, however I might need a little correction :blush:

“A:\IT\MARTIK03\TEST\Status Changes.xlsx” strnewFileName = “Status Changes_” + DateTime.Now.ToString(“yyyyMMdd”) + “.xlsx”

The highlighted part is a full path with file name.

1 Like

Hi @Martin_Kral

You can simply extract the path without file extension.

Strpath = fullpath.Substring(0, filename.Length - “xlsx”.Length)

Newfile = Strpath + “_” + ......

Regards,
Karthik byggari

1 Like

Im lost now :) Could you advise me, how my **Move File** destination should look like ? Along with full path and attribute to file rename. PS : Im newbie :slight_smile:

  1. Consider your file path is stored in the below string variable.

strFilePath = "A:\IT\MARTIK03\TEST\Status Changes.xlsx"

  1. Assign Activity for setting new file path with a date (create one string variable).

strnewFilePath = strFilePath.Substring(0, strFilePath.Length - 5) + "_" + DateTime.Now.ToString(“yyyyMMdd”) + “.xlsx”

After assign activity, strnewFilePath contains the following value -

A:\IT\MARTIK03\TEST\Status Changes_20190417.xlsx

  1. In the properties of Move File Activity, set the following
  • Path - strFilePath
  • Destination - strnewFilePath

Regards,
Karthik Byggari

6 Likes

It says “Filename is not declared”. Is there any field where should I put the filename ?

strnewFilePath = strFilePath.Substring(0, strFilePath.Length - 5) + “_” + DateTime.Now.ToString(“yyyyMMdd”) + “.xlsx”

1 Like

Hi @Martin_Kral,
first assign file name to a variable like

fileName = Path.GetFileName(“the file path”)

then manipulate the variable fileName as required. (means adding date)

then append the fileName variable to new path where the file to be stored.

1 Like

@KarthikByggari
It works !!! Thank you very very much for your support and patience :smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.