I want to find specific name of file with today's date information

Hi.

I want to find file like this

“c:\user\documents\2023-05-06_filename*.xls”
-I have to assign today’s date like that form (2023-05-06)

and, among that files, I have to find latest revised file.

Please help me

@hoseongwon Hi, You want to get file with specific word and current date. right?

@hoseongwon
Try this one.

So while you are converting Type Argument as object for ForEach Activity then do as below :-

item.ToString.Contains(DateTime.Now.ToString(“yyyy-MM-dd”))

I forget to mention above der only :sweat_smile:

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

@hoseongwon

Please try this

Directory.GetFiles("FolderPath",Now.ToString("yyyy-MM-dd") + "*.xls").OrderByDescending(function(x) new fileinfo(x).LastWriteTime)(0)

Cheers

Hi @hoseongwon

Try this-

  1. Use the Assign activity to create a string variable to hold today’s date in the desired format:
    Assign todayDate = DateTime.Now.ToString(“yyyy-MM-dd”)

  2. Use the Directory.GetFiles method to get all files matching the specified pattern:-

Assign filesArray = Directory.GetFiles("c:\user\documents", todayDate + “_filename*.xls”)

3.Use a For Each activity to loop through the filesArray and Inside the loop, use the Path.GetLastWriteTime method to get the last write time of each file:-

For Each file in filesArray
lastWriteTime = File.GetLastWriteTime(file)

  1. Use an If activity to compare the last write time of the current file to the last write time of the previous file:-

If lastWriteTime > previousWriteTime

  1. Inside the If activity, assign the current file’s last write time to the previousWriteTime variable and also inside the If activity, assign the current file’s path to a variable that will hold the latest revised file path:-

Assign previousWriteTime = lastWriteTime
Assign latestRevisedFile = file

Thanks!!

Thank you so much

1 Like

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