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