Delete files

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

Hi @arivu96,

I am trying to delete all the PDF file present in my project location immediately after workflow starts. I have gone through your workflow. I have a small doubt, I just want to know is there any other way to provide the project location without complete path like this
System.IO.Directory.GetFiles(“New folder”)

In-spite of providing complete file path from C: — like this
“System.IO.Directory.GetFiles(“C:\Users\v-aanbarasan\Documents\UiPath\blank\New folder”)”

For example, when we use excel application scope from the project lever we will mention it as “Excel File Name with extension” as shown below. We will not use complete path like “C:\Users\v-aanbarasan\Documents\UiPath\blank\New folder\TestDataFile.xlsx”

image

Please suggest :slight_smile:

Hello Sowmya,
In this video I do a lot of stuff with Files:

6:55 Delete files
8:15 Delete only PNG files
8:55 Delete all the files except PNG files
9:55 Move files
11:10 Delete files that are older than 2 weeks

Thanks,
Cristian Negulescu