How to get only yesterday file name from folder


I have the folder were it has three to four excel file with same name format along with date .i want only previous day excel file to move to another folder.
For example files in folder as Increment file 2020-06-03
Increment file 2020-06-02
Increment file 2020-06-01
All this files are in excel format.
in above scenario i what only Increment file 2020-06-02 and this file has to move to another folder.some time folder contain only one file which is yesterday file.
please guide how to do this.

Hi @vaish

You might achieve your goal by adapting the following to your needs:

Assign (String)
yesterday = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")

Assign (Array of String)
files = Directory.GetFiles(myDirectory, "*" & yesterday & "*")

files.Length = 1

  • Assign (String)
    result = files(0)


  • Throw
    New BusinessRuleException("How dare you?")

Use the following method to get previous date.“yyyy-MM-dd”)




files = Directory.GetFiles("" & yesterday & "")
In first * i have to replace with Folder path right,
and in last * do i want to mention Increment file?

oops, my bad, I edited my post as I forgot to pass the directory as argument :slight_smile:

basically, Directory.GetFiles(myDirectory, "*2020-06-02*") will look for files with name containing 2020-06-02 in myDirectory.

okay, variable for files is string right?
then i need to pass into for each activity is that right?

files is an Array of String, yes.

You can just take the first element if there is only one match. You can ensure that assertion by a condition if you prefer with files.Length = 1

Just edited again the answer :slight_smile:

i tried to print the files(0) am getting an error as Index was outside the bounds of error…

Can you


, please?

yeah it displays 0

and if you use

files = Directory.GetFiles(myDirectory)

and log each file in a ForEach, do you see the file?

its displaying three files.if its in for each …

That’s normal (you confirmed that no attribute handling prevent retrieving the listing).

Do you see the target file? (btw, I just checked with a log directory and the filter works as expected).

Sorry for this, actually i cross check with the input … i didnt find the yesterday file in that path. so i added now, am getting the excepted result .

But i have one doubt i display in the message it display the output along with path .
Now do i need to use move file activity

Thank you so much for your help, finally i got the excepted output. with the help of move file.

1 Like

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