I am in need to create an automation for the following below:-
Import the latest up to date .txt file into an excel (.csv - with column headers). Always choose the latest date of .txt file to import from.
*Eg. Import Today().txt from folder “C:\Users\FolderPath”
After importing is successful, generate into a new .csv file with "+Now.ToString(“ddMMyyyy”), save and relocate to “C:\Users\FolderPath2”
Open the .csv file, read range “A:Z” and VLOOKUP the info using the latest .csv file Eg. =VLOOKUP(A2,‘ExampleCSV’!A:Z,10,0)
Currently, I am stuck in trying to “Read text file” function where it keeps stating - “Absolute paths not recommended.Use Relative Paths etc…”
I have searched the forum for similar topics and tried the solutions. But when i create and assign strExample = Directory.GetFiles(“C:\Users\FolderPath”,".txt")*, I do not know how to read the text files from here.
To read the file with the latest date in its name in UiPath, you can follow these steps:
->Use the “Get Files” activity to retrieve all files in the directory.
->Use linq to get the latest file.
(From file In array_files
Let fileName = Path.GetFileNameWithoutExtension(file)
Let dateString = fileName.Substring(fileName.IndexOf(“_”) + 1)
Let day = Integer.Parse(dateString.Substring(0, 2))
Let month = Integer.Parse(dateString.Substring(2, 2))
Let year = Integer.Parse(dateString.Substring(4, 4))
Let dateValue = New DateTime(year, month, day)
Order By dateValue Descending
Select file).FirstOrDefault()
this LINQ query extracts the date from the file names, converts it into a valid date format, orders the files based on these dates, and then selects the file with the newest date.
Directory.GetFiles(“Provide your folderpath here”,"_“+now.ToString(“ddMMyyyy”)+”.txt").First*
Directory.GetFiles(“”) ← this here is to find and locate the directory of the folder paths
"_" ← what is this line for?
.First ← means it will always take the first file listed in the folder?