Get newest file in the directory

Hello everyone, Can somebody please tell me how to rename the newest file in directory?

have a nice day.

@tomaz

newestFile = files.OrderByDescending(Function(file) file.CreationTime).FirstOrDefault()

newestFile is a list
Use rename file activity

you should give the needed definition of newest from your requirements as newest can be:

  • based on creation date
  • based on parts from the filenname (e.g. date, sequence number)

Find some essential statements here:
[CheatSheet] - Filesystem APIs - News / Tutorials - UiPath Community Forum

HI @tomaz

  • Use this query for getting new file =New DirectoryInfo(Your Path).GetFiles().OrderByDescending(Function(f) f.LastWriteTime).First().ToString

  • After that Use the “Rename File” activity to rename the file

Hi @tomaz

Use for each file in folder.
Add filters as you need .
Use Rename activity.

Hope it helps!!

HI @tomaz

You can try in this way also!
str =Directory.GetFiles(“your folder name”,“*Your extension”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)

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