Delete files

uiautomation
studio

#1

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


#2

Hi sowmya,

Is there a pattern in the files name?

Bogdan


#3

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


#4

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


How to delete directories in a drive
#5

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 .


#6

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


#7

Hi @sowmya,

Refer below path

Regards,
Arivu


#8

have you made any changes
its looks like same


#9

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


#10

only the file contains date_Log.txt and date_DetailedLog.txt


#11

@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


#12

Not deleting the files


#13

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


#14

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


#15

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


#16

yes if i remove the date its working fine


#17

Hi @sowmya

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

Regards,
Arivu


#18

01-04-2018


#19

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


#20

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