In my usecase I want to check what is the last file index in that specific folder.For example in the above folder it is File3 - so the index is 3.For the next transaction run tomorrow , whenever this folder is accessed , the bot should check the index of the last file and create new file with (index + 1).
So the new file should be WEF12345_07092022_File4.xlsx ,WEF12345_07092022_File5.xlsx so on.
Everytime how do I check the index of the last file in any folder to add a new file with a (index +1)?
The format of the file name remains the same throughout - WEF12345_06092022_File(index)
Thanks for the response.
But how do I grab the latest index of the latest file from all the files present in the folder.
In the above case I want to extract only 3, not 1 and 2.
Hi @gokul1904 ,
in your case i assume highest number will be latest one. So you can give a condition of checking greatest number when you are getting the numbers and the highest you will be assigning in your case 3.
Or else if you want the latest file as per date creation and then do the opearations that can also be done.
As it looks like all the file names are following the same pattern, so what you can do is you can get all the file name in an array and order it in ascending or descending order as per your requirement and get the first or last index value from the list and use this regex
Hi @gokul1904 ,
I am attaching a code which will give you the latest xlsx file according to file creation time in a directory/Folder.
Please provide your folder path in the code. NewestFileIinDirectoryAnyDay.xaml (6.0 KB)
So, you got the latest file now you can perform the operations which I mentioned before
@gokul1904
why are you want to index from file name?
you just get file count form folder and add 1 to create new file name
for Example
you can get file count Directory.GetFiles(string path).count