Get the name of file.csv and continue with the number dynamically

Hello.

I’m reading values from a data table and I have to put it in a CSV file which is stored C:\test but inside this path, there are other CSV files and I have to obtain the name of the last file.

For example, if there were 1 , I’d have to create a CSV with the name “2”.

image

For example, if there were 1 and 2, I’d have to create a CSV with the name “3”.

For example, If there were 1,2, and 3, I’d have to create a CSV with the name “4”, and so on…

Desired Output
The bot has to get the last number of the name of the files inside C:\test and create a file.csv with the last number increased by 1 and paste the data table.

It has to be dynamic.

I think I’d have to create a new csv and try to obtain the names of the file inside the path and try to increase the number but I need help, please.

But there is not a csv activity to create a csv file just to move the dtable from an excel to the path of the csv.

I’m uploading the xaml.file and the excel file and csv.

I can’t upload the csv file but the workflow of the xaml.file needs to have a 1.csv in C:\test and It would work.

Help, please and thanks.

c1.xlsx (65.2 KB)

Main.xaml (10.2 KB)

@pprin001

So to get the latest file you can use below

latestfilenumber = Cint(Path.GetFileNameWithoutExtension(Directory.GetFiles("FolderPath","*.csv").OrderByDescending(function(x) Cint(Path.GetFileNameWithoutExtension(x)))(0)))

This will give you the latest number filename in integer format…

Now use (latestfilenumber +1).ToString for the new file

For writing datatable to csv please use write csv activity…

Cheers

1 Like

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