@retrieve each file in directory last modified

Hi,

How can I retrieve the files from directory from last modified time stamp?

Thanks
Girish

Hello!

Have you tried to search on the Forum before creating the post?

There’re a lot of posts with the same doubt that you are.

Anyway, here’s the solution:

Hope It Helps.

Regards,

Hey @Girish

You can use below linq to get all modified files from directory

DateTime to_date = DateTime.Now;

var files = directory.GetFiles().Where(function(file) file.LastWriteTime= to_date);

Tip - To use Linq you have to import System.Linq in your project Namespace.

Regards…!!
Aksh

2 Likes

Hi Akshay,

Can I enumerate the files to process?

Thanks
Girish

Actually I am looking for a solution to retrieve the files in order and process
I have 4 files in my directory I need to get one by one to process.
While running workflow it will generate the same time stamp but those are in sequentially ordered in directory

1)Assign DirectoryInfo dif=new DirectoryInfo(directoryname)
assign dif.Refresh()
Assign datetime dt to dif.lastwritetime.

2)You can also use Directory.GetLastWriteTime to get last created directory
3)Use recursive new DirectoryInfo(path).GetDirectories(“*”,
SearchOption.AllDirectories).OrderByDescending(d=>d.LastWriteTimeUtc).First()

2 Likes

Hi Bikash,

I tried third one it is not working.
For d=>d.LastWriteTimeUtc).First() not working
Properties for that not getting populated

Will give you first one result only.

Yes check the return type otherwise just use

DateTime to_date = DateTime.Now;

directory.GetFiles().Where(function(file) file.LastWriteTime= to_date).ToArray();

Hi Akshay,

File.Lastwritetime property is not displaying
Could you please check the syntax once

Imported System.linq? namesapce? otherwise share your workflow

Yes imported the System.Linq namespace
directory.GetFiles().Where(function(file) file.LastWriteTime== to_date).ToArray();
Will be assigned to what type of variable?

System.IO.FileInfo

@Girish - How to sort directory files using last modified date and name - #2 by aksh1yadav

and as per your need to get modified files for a particular date, please see attached sample.
Get Todays All Modified Files Details.xaml (6.8 KB)

Regards…!!
Aksh

5 Likes

Hi Akshay,

Thank you so much.
It is working fine for me.

Regards,
Girish

1 Like

I am trying to do something, slightly similar to this post.

I need to save a file with a date time stamp, during the process I then attach this file in an email. The file path is made up of variables and then datetime.now.tostring("dd-mm-yy); in the attachments section of the send outlook activity, I use the same variables and time stamp for the filepath (as I was to attach the same file)

but naturally an error occurs as the time has no moved on since i saved the file originally. Any way around this??

I have to use a date time stamp to save the file originally, and I just need to attach it again in an email further down the line, so need help in figurign out how i can attach this same time stamped file

thanks!!

Hi,

You can get the file from directory you have saved the file.
Since it was last modified file irrespective of name.
you can get the file using last modified in that directory and attach same in your mail.
To get latest file from your directory write below code:
directory.GetFiles("C:\Users\rkolli\Downloads",“Employee.xls”,searchoption.AllDirectories).orderbydescending(function(f)f.creationtime).first()

hi @aksh1yadav

I had gone through below solution , want to store latest file name in string irrespective of day/date , to process further , kindly help me in getting file latest file name in message box, not in loop , attaching zip as sample.

tnx & rgds
Aditi

image

Get Latest File.zip (71.0 KB)

Hello @aksh1yadav I could do it my self with the help of below post

Thnks :slight_smile:

Can you please share?..

Best regards

hi @beesheep PFA

Sample Latest File Name.xaml (9.9 KB)

3 Likes

Awesome thanks for sharing :sunglasses::sunglasses::sunglasses::sunglasses: