Rename_File

Hi Expert,

I wish to rename the file which is received as date format(“yyyyMMdd”) in every day. So I need to rename the file dynamically . The below mention path is my file is location path. Please suggest me to achieve this. Expected output to be the csv file will rename as HOLD REPORT.xlsx

“D:\LinQ\DAte\Forum\Input\GST Hold Report 20240205\GST Hold Report 20240205.csv”

Regards,
Balachander P

@Balachander_Pandian

If you just rename as csv it would not wokr…file would be corrupted

first to get the latest file you can sue for each file in folder sorted with creating date so that you get the latest

then inside that use excel file activity and pass the csv file and then use save excel as activity and try to save

if it does not allow…intead of save as use a write csv and before the read the excel data using read range adn pass the datatable to csv

cheers

Hi @Anil_G Thanks for information. No require to change the file format. Just need to rename the .csv file itself.

“D:\LinQ\DAte\Forum\Input\GST Hold Report 20240205\GST Hold Report “+DateTime.Now.ToString(“yyyyMMdd”)+”.csv”

@Balachander_Pandian
Assign:
FileDirectory = “C:\Path\To\Your\File\Location”

Assign:
SearchPattern = DateTime.Now.ToString(“yyyyMMdd”) & “*.csv”

Assign:
SourceFilePath = Directory.GetFiles(FileDirectory, SearchPattern).FirstOrDefault()

Assign:
DestinationFilePath = Path.Combine(FileDirectory, “HOLD REPORT.xlsx”)

If (SourceFilePath is not null and SourceFilePath <> “”)
File.Move(SourceFilePath, DestinationFilePath)
Else
Log Message: “No CSV file found for today’s date.”

@Balachander_Pandian

Then use for each file in folder…then use rename inside it…can use break to break after one filenmae change

cheers

hi @Krishna_Raj can you share the workflow

Use copy file activity or move file activity.

Enter- “D:\LinQ\DAte\Forum\Input\GST Hold Report “+now.tostring(“yyyyMMdd”)+”\GST Hold Report “+now.tostring(“yyyyMMdd”)+”.csv" in From file section

and in to section enter
“D:\LinQ\DAte\Forum\Input\GST Hold Report “+now.tostring(“yyyyMMdd”)+”\Hold Report.csv”

Hi @Balachander_Pandian

  1. Use For Each File in Folder Activity
  2. Use IF Condition with expression

CurrentFile.Name.Contains(Now.ToString(“yyyyMMdd”))

  1. Use Rename File Activity
  2. Break (IF want to Rename only one file ELSE not use Break Activity)

Hope it will helps you :slight_smile:
Cheers!!

Hi @Balachander_Pandian

There is a simple soultion as Anil_G already mention to get the latest file in that folder & rename it as you want.

Just replace the folder path at YourfolderPath in below expression, it will give you latest CSV file in that folder then by using rename you can change the name.

Directory.GetFiles(“YourFolderPath”,“*.csv”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)

Hope this helps :slight_smile: