How to pull out all files with modified date less than seven days in a folder?

I want to get file path of a file that was modified within 7days after system date, without using for each. thank you!

@Kelsey_Dane,

Check with this line of code in An Assign Activity. This will return you a list of files in this type - List(Of FileInfo) - System.Collection.Generic.List(Of System.FileInfo)

Directory.GetFiles("yourDirectory").[Select](Function(f) New FileInfo(f)).Where(Function(f) f.LastWriteTime < DateTime.Now.AddDays(-7)).ToList()
1 Like

hi!
Thanks for this, it works but I am getting this output.
“System.Collections.Generic.List`1[System.IO.FileInfo]”, I am trying to get the file path. thanks

Hi @Kelsey_Dane,

Once you get list. Use for each and print item in write line. You will have your file name within the expected range.

Thanks

1 Like

I tried your suggestion but it runs through all 2000 files in the folder even if the modified date of the file is less than 7days. I wanted it to take only the file paths in the folder with the recent modified date without using for each to lessen the time. thank you

Hi @Kelsey_Dane,

Let us know the date format of files.

date format is “mm-dd-yyyy”

Hi @Kelsey_Dane ,

Try this,

Directory.GetFiles(“yourDirectory”).[Select](Function(f) New FileInfo(f)).Where(Function(f) f.LastWriteTime < CDate(DateTime.Now.AddDays(-7).ToString(“MM/dd/yyyy”))).ToList()

And then print the list count to check.

Thanks

its still not working, maybe i missed something, i have attached here the sample sequence. thank you

getfilemodifiedrecently.xaml (11.3 KB)

It works for me.

I used :- Directory.GetFiles(“C:\Users\Jayesh\Desktop\Desktop Files”).[Select](Function(f) New FileInfo(f)).Where(Function(f) f.LastWriteTime < CDate(DateTime.Now.AddDays(-7).ToString(“MM/dd/yyyy”))).ToList()

Thanks

1 Like

Thanks! it finally worked! i happened to put in a type of array. I need to run this on 3000 folders, can you help how to set this up? thank you

Hi @Kelsey_Dane ,

ArrayVariable= yourlistvar.toarray

1 Like

can you please elaborate? this would read all the 3000 folders? directories? thanks

Oh, okay, then you have to use for each… it will generate list variables for you.

1 Like

Thank you!! I’m now working on it! I just have to finalize everything, yay!

1 Like

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