Need to use the last file but copy past does't save the real date and time

I use copy file to create a new file and write into it, after that i use the below sentence to take the last copy file i created but the file date is similaire to the original one and its not the real date and time
Directory.GetFiles(ExcelFile1).OrderBydescending(Function(d) New FileInfo(d).LastWriteTime).First

image

Hi @Soudios
Have you tried printing/debugging the name of the file?
It’s possible that if there’s no delay after the program is done writing to the file, then a temp file that is named something like ~Your Original File.xlsx may be the one that matches the LastWriteTime filter.
Try to debug the file being returned, and make sure the file is closed or that the write is complete and file is saved before attempting this.

I hope this helps.

Hi @RPAForEveryone

It takes an existing and old file i don’t understand why

Have you tried these already existing, solved forum threads?

The solution suggests code very similar to your code here, but with slight difference.
I hope one of them will help you find what’s missing in your code.

I believe You are taking the date modified date of the file. The Date modified for the file will be created when it is modified/renamed or any changes with file. Date created should be appropriate to take as it takes the time and date when the file is created in that specific folder. Hope this helps.