Hi I am trying to copy one of the existing file and replace the name partially with a T-1 business date, and pasting it at the same location. I wonder how exactly can I do it.
Example: copy “file XYZ 20220316” from folder A–> change copied file name from “file XYZ 20220316” to “file XYZ 20220317” → paste the “file XYZ 20220317” to folder A
Hello @Nicholas_Yu
Welcome to UiPath community…!
As per the statement, you are trying to rename the file in folder A. So you can directly use the activity, rename file.
Thanks
Hey
you can use the copy file activity

and then just rename that copied file

Regards
Hello @Nicholas_Yu , welcome to UiPath Community
you can use the Copy file activity, where need to provide the file path with its extension (.xlsx,.txt,.xlsb). Also the destination with the name that you need to modify and use the same file extension.

HI @Nicholas_Yu
Welcome to Community!
You can do like this
- Use Copy file activity and in the destination use this
"file XYZ "+DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match("OnlyFilename with date.extension","\d+").ToString,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).AddDays(1).ToString("yyyyMMdd")+".extension"
Regards
Sudharsan
Hi Sudha, I am getting this error " Illegal characters in path." But I believe its the correct approach.
Fyi the file I am trying to copy and rename (+1 day) is an excel file with the following naming “XYZ 2023 01 17” Can you kindly assist me with the destination commend
Checkout this expression @Nicholas_Yu
"XYZ "+DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension("C:\Users\Foldername\XYZ 2023 01 17.xlsx"),"\d{4}\s\d{2}\s\d{2}").ToString,"yyyy MM dd",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).AddDays(1).ToString("yyyy MM dd")+".xlsx"
Also can you send full path here?
From
My Documents\UiPath testing\file XYZ 20220316.xlsx
And the to should be like this right?
You can try this @Nicholas_Yu
"My Documents\UiPath testing\file XYZ "+DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension("My Documents\UiPath testing\file XYZ 20220316.xlsx"),"\d+").ToString,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).AddDays(1).ToString("yyyyMMdd")+".xlsx"

Regards
Sudharsan
I am still getting an error, is it possible for you to try name an excel sheet as “AAA BB - CCC BBB - 2023 02 14” and copy it by adding 1 day.
From:
My Documents\UiPath testing\AAA BB - CCC BBB - 2023 02 14.xlsx
How many type of file name do you have ? @Nicholas_Yu
file XYZ 20220316.xlsx
AAA BB - CCC BBB - 2023 02 14.xlsx
Any other do you have ?
"My Documents\UiPath testing\AAA BB - CCC BBB - "+DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension("My Documents\UiPath testing\AAA BB - CCC BBB - 2023 02 14.xlsx"),"\d.+").ToString,{"yyyyMMdd","yyyy MM dd"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).AddDays(1).ToString("yyyyMMdd")+".xlsx"

Illegal characters in path
Can you share the expression which you used @Nicholas_Yu ?
From
<[Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)]>\UiPath testing\AAA BB - CCC BBB - 2023 02 14.xlsx
To:
“My Documents\UiPath testing\AAA BB - CCC BBB - “+DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(“My Documents\UiPath testing\AAA BB - CCC BBB - 2023 02 14.xlsx”),”\d.+”).ToString,{“yyyyMMdd”,“yyyy MM dd”},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).AddDays(1).ToString(“yyyyMMdd”)+“.xlsx”
Try this in from field@Nicholas_Yu
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+"\UiPath testing\AAA BB - CCC BBB - 2023 02 14.xlsx"
Illegal characters in path
I dont think it is anything to do with the From field commend, as I selected the file via clicking on the “Browse for file”,
“<[Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)]>\UiPath testing\AAA BB - CCC BBB - 2023 02 14.xlsx” is generated through the system.
I think the problem is, UiPath isn’t able to recognize where I wanted to paste the file to
Can you share screenshot @Nicholas_Yu ?
Checkout this @Nicholas_Yu
Use the below expression in the Advanced Editor

From
string.Format("{0}\AAA BB - CCC BBB - 2023 02 14.xlsx", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
To
string.Format("{0}\AAA BB - CCC BBB - "+DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(string.Format("{0}\AAA BB - CCC BBB - 2023 02 14.xlsx", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))),"\d.+").ToString,{"yyyyMMdd","yyyy MM dd"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).AddDays(1).ToString("yyyyMMdd")+".xlsx", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
Regards
Sudharsan