How to copy excel file and change the file name?

Hello,

I’d like to make below process. Could you please help for this?

  1. If there is no current date file, copy last month file.
  2. Change the file name to yyyy-MM(This month)
  3. Save

image



Directory.GetFiles(“D:\Users\01048398\Desktop\Treasury_CashReport_Final”,""+Today.ToString(“yyyy-MM”)+".xlsx")

You can use a copy file/move file activity and your desired file name. Don’t forget to include the file extension.

@kenneth.m Thank you for your comment.
I’ve tried to rename the target file with Move File activity but faced below error message.
which script should I change ?

Hi @Dorothy_lee

Please refer the below link.

Hello~
Could you please review which part is wrong?
FileSystem.Rename(“D:\Users\01048398\Desktop\Treasury_CashReport_Final\template”,“D:\Users\01048398\Desktop\Treasury_CashReport_Final\Today.ToString(“yyyy-MM”)”)
image

Hi @Dorothy_lee

Please mention the file name in existing path details. I have attached screenshot for your reference.

Happy Learning :slightly_smiling_face:

It should be coded like this. FileSystem.Rename(“D:\Users\01048398\Desktop\Treasury_CashReport_Final\template”,“D:\Users\01048398\Desktop\Treasury_CashReport_Final\" + now.ToString("yyyy-MM"))

You can see no error in the invoke code

image

Please add the proper file extension of your file name…Please see the example below…

FileSystem.Rename(“C:\Users\giris\Desktop\text.txt”,“C:\Users\giris\Desktop\text-" + now.ToString("yyyy-MM") + ".txt")

My Output
image

hi @Dorothy_lee,

Please separate the Today.ToString from the file path (i.e. “D:\Users\kenneth\Desktop\Folder Name\”+Today.ToString(“yyyy-MM”)+".xlsx"

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