LINQ Query to get all the files from Directory whose Last Modified Date > (Current Date-15)

Hi Team,

Could you please help me for writing LINQ Query for getting all bthe files from folder whose Last modified date > (CurrentDate-15)

Thanks in advance !!

Hi @avinash_ghanwat1

Assign: currentDateMinus15Days = DateTime.Now.AddDays(-15)

For Each (item) in Directory.GetFiles(“your_directory_path”)
If
File.GetLastWriteTime(item) > currentDateMinus15Days
Then
// Perform actions with the file
End If
End For Each

Hope it helps!!

1 Like

@avinash_ghanwat1

Try this

Directory.GetFiles("FolderPath").Where(function(x) New FileInfo(x).LastWriteTime> Now.Adddays(-15))

cheers

1 Like

@avinash_ghanwat1

Variable: files (Array of String) Value: Directory.GetFiles("C:\YourFolderPath").Where(Function(file) File.GetLastWriteTime(file) > DateTime.Now.AddDays(-15)).ToArray()

For Each Activity:

1 Like

Hi @avinash_ghanwat1

Check the below linq expressions to get all the files from Directory whose Last Modified Date > CurrentDate-15

Directory.GetFiles(FolderPath).OrderByDescending(Function(d) NewFileInfo(d).Creation>DateTime.Now.adddays(-15)).toList()

Hope it helps!!

1 Like

@avinash_ghanwat1

string folderPath = @"C:\Your\Folder\Path";
            DateTime currentDate = DateTime.Now;
            DateTime fifteenDaysAgo = currentDate.AddDays(-15);

            string[] files = Directory.GetFiles(folderPath)
                                     .Where(filePath => File.GetLastWriteTime(filePath) > fifteenDaysAgo)
                                     .ToArray();

VB:

FoolderPath As String = "C:\Your\Folder\Path"
         currentDate As DateTime = DateTime.Now
         fifteenDaysAgo As DateTime = currentDate.AddDays(-15)

        files As StringArray = Directory.GetFiles(folderPath).
                                 Where(Function(filePath) File.GetLastWriteTime(filePath) > fifteenDaysAgo).
                                 ToArray()
1 Like

Actually I have implemented workflow using UiPath Activities but need to use LinkQ, Thanks Anyways

@Anil_G : Thank you for the quick response, Its working as expected.

1 Like

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