Delete Excel File after 14 days

Hello everyone,

I save an Excel file in a folder every day. Now I want all files in the folder to be deleted whose created date is more than 14 days.

I would appreciate your help.

BR
Chetan

Hi @Chetan_Wagh ,
You can get file after 14 days by date created


if you need get all file date = now -14
file.CreationTime.Date.ToString = DateTime.Today.AddDays(-14).ToString

if you need get all file date is more than 14 days.
file.CreationTime.Date.ToString < DateTime.Today.AddDays(-14).ToString

hope it help,

2 Likes


@Chetan_Wagh can u try with this
And also refer this thread : Delete file with yesterdays date - Help - UiPath Community Forum

3 Likes

@Chetan_Wagh

this will give you all files older than 14…use a for loop and delete file inside it

System.IO.Directory.GetFiles("Folder",".xls*").Where(function(x) Cdate(New FileInfo(x).CreatedDate)<=Now.AddDays(-14))

cheers

1 Like

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