Get latest Text file from folder


I have a scenario like

1 there are multiple text files in that how to get the latest modified text file based on date created/modified in a same folder
2 once get the latest text file (file contains inside data is like : date ended on 15/4/2021) if date ended on string is present at last line in text file then using that send one sample mail
ex : if (text file data is date ended on then trigger mail)

Thanks & Regards
Veeresh M


Can any one suggest me.

Hi Veeresh,
follow these steps to get latest file

  1. Use FileSearch activity - this activity will generate one excel file which contain files details include. File Name, File Path, Owned By, Creation Date, Last Modified At, File Size In KB, File Type
  2. Use Advance loop - excel - this activity will help you to sort data in desc order based on column (Creation Date)
  3. Within loop - store file path in first iteration and use Break loop activity to come out from loop
    you will get latest file path.


You can use also use a powershell script to achieve your use case

Amit Anand

Yes @mundarinti.veeresh

This scenrio would be easier to automate using Powershell.
Use below command to get the last modified file.

gci DirectoryPath [-fi PatternOfFileName] | sort LastWriteTime | select -last 1 fullname -ExpandProperty fullname

Once you get the file name, remove additional charcters and then using the same path, read the content of your Notepad file by Another Powershell command

Get-Content filePathofTextFile

Then do a comparision check with your condition and send the mail as per the output.

If this solves your issue, please mark the answer as Solution. :slight_smile:

Hi Prateek,Bhuvan,Anand

Thank you for the help. It is working fine as expected using above all scenarios.

Thanks & Regards
Veeresh M