Open file in directory

Every day 2 files will be created (there is no time period when file will be created), so bot need to identify which is created recently and open the file.
File name will be “COLLECTION_REPORT_yyyyMMDD_HHMMSS”.

Please help me with the logic.

@hemanth_chinna, Kindly search our forum, you will find most of the soutions

  1. How to sort directory files using last modified date and name - #2 by aksh1yadav
  2. Get the latest created folder's creation date from a directory - #2 by aksh1yadav

Regards,
Dominic :slight_smile:

Hi @hemanth_chinna
We have .net code to find recently created file .
Try with that
Directory.GetFiles(“dir_path”).OrderByDescending(function(d) new FileInfo(d).CreationTime)(0)
This commad provide recently created file from specified directory.
Regards,

newtest.xaml (14.0 KB)

I tried with this code, but it is not working.

@hemanth_chinna, Have gone through your xaml. ‘\’ was missing between the directory and file name.
I think you could figure out right file through message box. But the problem is in Path Exists activity

Regards,
Dominic :slight_smile:

@Dominic
I placed "" this in code, in message box I am able to get the path of the file. Path Exists activity is showing false.
Because “COLLECTION_REPORT_yyyyMMdd_HHMMSS” in this I am able to get exact date which is on file but time difference is occurring, so Path exists activity is showing false.

@hemanth_chinna,
This is just because in the very first assign activity, you have used
Ist Method - Directory.GetLastwritetime which gives the directories last write time

Actually you need to use this,

to get the IInd Method - latest modified time of a file

Lemme exemplify,

CASE A : Folder A - created at 12:30 P.M and its time was modified as two new files one at 12:31 P.M and other at 12:32 P.M was created. Now the modified time of folder will be 12:32 P.M
In this case latest file & folder time will be same

CASE B: Folder A - created at 12:30 P.M and its time was modified as two new files one at 12:31 P.M and other at 12:32 P.M was created. Then you have renamed the file at 12:33 P.M.
Now the modified time of folder will be 12:33 P.M whereas file time will still remain at 12:32 P.M

So handle this accordingly with the second method as it matches your exact requirement

Regards,
Dominic :slight_smile: