How do I get the lastest file in the folder


#1

I have a folder with three files tes1_v1.xls, test2_v2.xls, test3_v3.xls. test3_V3.xls is the latest file.

How do I move the latest file to a new folder.


#2

Directory.GetFiles(folder_path,".xlsx",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)


Find latest File in a folder with respect to date Created
How to sort the files in a specific folders descending way and select the 1st/latest file in uipath?
Find latest File in a folder with respect to date Created
How to read and write file name with current date
#3

Could you please explain what is “OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)”


#4

Sorts files by creation time and takes top 1 file


#5

What is “(Function(d) New FileInfo(d)” …

I have two files in the folder-

I have used the statement-
Directory.GetFiles(Filepath,“100”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)

I am getting this result -

Please help !!


#6

Try 100*.xlsx


#7

getting same error !


#8

That doesn’t look like error…try getfile(0).ToString


#9

did not work :frowning:


#10

It works with

Directory.GetFiles(folder_path,".xlsx",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)


#11

Hello All,

Can you please add the XAML file, I am in same situation, your help is appreciated.

Thank you!


#12

I am travelling and don’t have access to the system for XAML.

But see if this helps.

dir = Directory.GetFiles(folder_path,".xlsx",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).Lastwritetime)

msgbox dir (0).
— dir is IENumerable variable


#13

@sampaddas :
I tried the suggestions mentioned here,
for Directory.GetFiles(folder_path,".xlsx",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0), I got indexoutofrange exception.

for Directory.GetFiles(folder_path,".xlsx",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1). I got System.Linq.Enumerable+d_24`1[System.String] error.

Can you please suggest me a way out of this?


#14

dir is ienumerable = Directory.GetFiles(“Folder_Path”,“File_Name”,SearchOption.AllDirectories).OrderByDescending(Function(x) New FileInfo(x).LastWriteTime)


#15

I m getting below error

‘getfiles’ is not a member of system.collection.IEnumberable.How to rectify this.help plx

Assign activity:
directory = Directory.GetFiles(,“task_sla.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)

directory is in IEnumerable datatype