To read previous created file

Hi all

i am having multiple files in folder with timestamp created i want to read only latest/previous file … eg. consider file_12.01 pm.xlsx,file_12.30 pm.xlsx i want to read second file which is latest …

How can i do that

thanks

hi @Pankaj_Dhane,

Take 1 assign activity as given below,

LatestFile (String) = Directory.GetFiles("FolderPath","*.xlsx").OrderByDescending(Function(r) New FileInfo(r).CreationTime)(1)

Note - Put your folder path in a query, this will get all .xlsx file names in from a folder and take out 2nd latest filename and store it in LatestFile var. now you can use that var in Read Range activity.

thanks @samir i will try this solution

User this instead in the assign activity:

LatestFile (String) = Directory.GetFiles("FolderPath","*.xlsx").OrderByDescending(Function(r) New FileInfo(r).CreationTime)(0)

1 will give you second file,
0 will give you latest file.

1 Like