How to delete the old excel file from a folder

Hi All,

I want to delete the excel files from a folder which contains more than 4days old
for example I should keep the excel till 28-4=24/09/2022, before 24/09/2022 excel I need to delete.
the excels contains inside the folder :
“\\Software Data\Automation\NaveenKumarS\ModmedInventory\ModmedRejection28092022”.

Please do needful.


Is it a File name or folder name?

That is folder name which will create daily on basis of current date

inside that folder excels are present

Hi @HeartCatcher

Check out the XAMl file

DeleteFile.xaml (5.7 KB)


Here is the one line code, using Invoke code you can achieve it

array.ForEach(Directory.GetFiles(“YourFolderPath”).Where(Function(x) New FileInfo(x).LastWriteTime.Date < Today.Date.AddDays(-26)).ToArray,Sub(x) File.Delete(x))

If are would like to proceed with regular method…take the below code and paste it in the For each and then use Delete activity…

Directory.GetFiles(“YourFolderPath”).Where(Function(x) New FileInfo(x).LastWriteTime.Date < Today.Date.AddDays(-26))

Hi @HeartCatcher

Loop each excel files from folder
Directory.GetFiles(“\\Software Data\Automation\NaveenKumarS\ModmedInventory\ModmedRejection28092022”,“*.xlsx”)

in if condition (Directory.GetCreationTime(item.ToString).ToShortDateString.CompareTo(

Filepath=\\Software Data\Automation\NaveenKumarS\ModmedInventory
Inside above path there are 4 folders:

I need to keep ModmedRejection28092022,ModmedRejection27092022
and rest should be deleted

Kindly refer this XAML file, it may help you (70.2 KB)

I am unable open your file, coming error like unresolved activity

Share some screenshot

What screenshots??

Error screenshots

Please send the logic which you applied in uipath studio, by taking photo

This error I am getting


  1. Use For each folder in folder activity.
  2. mention the folder path which contains ModmedRejection24092022 and more folders
  3. Assign Days=2 , because of filter last 2 days and days should Integer
  4. Use assign and separate the date from the folder by

FolderdateString was the variable type of string
  1. Convert it to date format

where folderDate was variable type of  System.DateTime
  1. Use If condition to filter folder
  1. Then sequence use Delete Folder



update the pacakage Uipath.system.activities