Deleting csv file


I am looking to delete a file form a folder but dont want to delete all the files in the folder.
Basically the file will be open by UiPath and run through the process on the server which at the end of the process i will need UiPath to pick up a specific name of file to delete.

Can anyone help me?


Hi @nick.v

Use Delete activity to delete the file pass the path in property pane


The file is kept on a server rather than a folder.
The name of the file will be different each time the process is run.

However there are words like ‘Invoice’ that will be present, it there a way to locate the file using word recognition to delete the file?

@nick.v Check this code it will give list of file names in an array

Hope these steps would help you resolve this
—use a assign activity like this
arr_filepath = Directory.GetFiles(“yourfolderpath”,”Invoice.csv”)

Where arr_filepath is a variable of type array of string

—now pass this variable as input to for each activity and change the type argument as string in the property panel of for each loop activity
—inside the loop use a DELETE activity and mention the file path as item.ToString

—this will all the files with csv file type and having invoice as a word in its Filename

Cheers @nick.v

the file thats saved on the server doesn’t have ‘Invoice’ written in it however it will have invoice written in the file itself.

i was thinking if i used get ocr text to find the text ‘Invoice’, then move on to a IF statement if the condition is true to delete the file if its false to leave the file where it is.

would this work?

The file wouldn’t need to be opened as on the server once you click on the file there is a preview screen where you can see if the word ‘Invoice’ is present.

But didnt you say the process will open the file? How do you know which one you will open? If you need to open several files, to see if invoice word is inside, use read text file not ocr…

no the process won’t open the file however it will go to the location of the file, i know of a few file names that i need to delete which is fine i can do that with click activity. However i have other files there which if they have the word Invoice in them i would need to delete.

I also don’t know how many files will be located there on some days it will be 10 other days 3 therefore need to add a loop into the process until all the files have been checked.

How do you “go” to the files location? when you say they are on a server, do you have that path like “\\server\folder”?

Hi, the files are contained in a server based application which has its own pdf viewer.
It is a custom CRM system.

oh ok understood, then if your application dont have a built in file viewer, you may need to download each one and search for the string inside to be able to find the one to delete…

it is not possible to download the files, i can open the file to view only.

oh, so even better :slight_smile: just try a get text on that instead. Unless it is an image preview…

its an image preview on their server so i can’t download the file

being a preview, does that mean that you cant see the whole text and might not be able to identify the word Invoice? If yes, then maybe a simple image activity might do the trick…

I can view the full document when changing the zoom, however the word invoice may not be written in the same place on every document.

you should zoom out until all preview is visible, then use find image surrounding the Invoice word.