Delete files

i want to delete the log files(.txt files) which is created on daily basis in project folder
and want to delete the files which was created in one week before for every week
can anyone help me in this

Hi sowmya,

Is there a pattern in the files name?

Bogdan

format1 : 01-04-2018_DetailedLog.txt
format2 : 01-04-2018_Log.txt

Hi @sowmya,

Refer this xaml file to delete .txt file from particular folder and created date one week before
Main.xaml (8.6 KB)

It will not check the format of the text file, it ll look only created date.

Regards,
Arivu

For this pattern you could use something like Date.Now.AddDays(-7).toString+"_DetailedLog.txt". It’s not the exact function because you will need to make the date look something like 01-04-2018 as right now will look something like 01/04/2018 00:00:00 .

it has deleted other text files which were created one week before:(

Hi @sowmya,

Refer below path

Regards,
Arivu

1 Like

have you made any changes
its looks like same

yes @sowmya same xaml file.

in that xaml file-> will delete the all the text file in the folder and created one week before.
do you need to delete particular text file alone??? or any other requirement ??

Regards,
Arivu

only the file contains date_Log.txt and date_DetailedLog.txt

@sowmya,

ok then change the if condition instead of “.txt” use “_Log.txt” and “DetailedLog.txt”.
if condition update this code.
(System.IO.Path.GetFileName(item).contains("_Log.txt") or System.IO.Path.GetFileName(item).contains("_DetailedLog.txt")) AND
System.IO.Path.GetFileName(item).contains()
Convert.ToDateTime(FilePath.GetCreationTime(item.Tostring())<System.DateTime.Now.AddDays(-7)

Regards,
Arivu

Not deleting the files

getting the starrfile Value as system.string and if condition is false always even i have file which created one week before

Hi @sowmya,

i checked in my local its working fine can you check again.

did updated this code in if Condition

(System.IO.Path.GetFileName(item).contains("_Log.txt") or System.IO.Path.GetFileName(item).contains("_DetailedLog.txt")) AND
System.IO.Path.GetFileName(item).contains()
Convert.ToDateTime(FilePath.GetCreationTime(item.Tostring())<System.DateTime.Now.AddDays(-7)

Regards,
Arivu

Hi @sowmya,

yes starrfile will get as string array only.i think date is the problem can you remove date condition alone and check it.

Regards,
Arivu

yes if i remove the date its working fine

Hi @sowmya

can you check the which date you are created the text file.

Regards,
Arivu

01-04-2018

use this one
(System.IO.Path.GetFileName(item).contains("_Log.txt") or System.IO.Path.GetFileName(item).contains("_DetailedLog.txt")) AND
Convert.ToDateTime(FilePath.GetCreationTime(item.ToString())<System.DateTime.Now.AddDays(-7)

Regards,
Arivu

1 Like

its working if i try with GetLastWriteTime function (System.IO.Path.GetFileName(item).contains("_Log.txt") or System.IO.Path.GetFileName(item).contains("_DetailedLog.txt")) AND Convert.ToDateTime(FilePath.GetLastWriteTime(item.ToString())<System.DateTime.Now.AddDays(-7)

Regards,
Arivu