Delete a file from folder

Hi Champs,

It would be a great help. If someone could guide me. I am creating a temp xlsx file to do some manipulation but after doing manipulation i have to delete the file . How can i delete the file by the name . i dont want to provide folder path as the file would be in the project folder . All i want is to delete the file by its name.

Thanks !!

1 Like

Hi @Shikhar_Tandon, Are you creating a file or downloading a file? If creating a new file, you cannot create a temp.xlsx without specifying the location of the file? (Correct me if not)

use delete activity, after making sure it is released by the process.

2 Likes

@Shikhar_Tandon Delete Activity actually worked without giving the location of the file if it is stored in the project folder.

it is by default, if you dont give a folder it uses project location for all activities that uses a path property.

Hi
—we can use EXCEL APPLICATION SCOPE and mention the file name so that it will create a new file in the project folder itself
—and we can mention the same Filename in DELETE activity so that it will get deleted from the same project folder

Cheers @Shikhar_Tandon

Hi @Harshav thanks for response. I tried this but the file is not deleting that’s why i posted the topic

thanks !!

hi @Palaniyappan, thanks for the reply, i have tried this but the bot is stopping and is not deleting the file it is giving error. please help.

thanks!

1 Like

@Shikhar_Tandon

I think your excel application is still holding the file after your manipulation.
Just do the following

  1. Kill EXCEL application first once you complete the manipulation
  2. Delete after the kill operation

Hope this will work.

What kind of manipulation are you doing that really needs an excel file to exists if you delete it before the process ends? can this be done using only DataTables?

fine
if possible can i have that error screenshot
cheers @Shikhar_Tandon

Well,

If you are facing issues deleting a xlsx file using the inbuilt activity you can use Invoke code or invoke code or invoke method.

Code is what I use so here you go.

You create an application as

Excel.Application YourXlObject= new Application();
Path.GetTempPath+YourXlsxFileName - (here is where you create your temporary excel file to be read or copied or created)
In the end for releasing the object you can use the folowing

YourXlObject.Quit();

OR

EXCEL.kill(); // this method accepts the process name and kills it - use it as a last resort.

OR

if (YourXlObject!= null) Marshal.ReleaseComObject(YourXlObject);

The namespaces are - System.IO, System.Diagnostics, Microsoft.Office.Interop.Excel.

These should be used in Invoke code activity and change the language to C# or if you want VB just look up the Syntax in google.

Hope this helps.

Regards :slight_smile:

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

1:10 Download the file and Move the latest file to folders
4:30 Rename files with VB commands
6:00 Move files to do Rename
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
14:40 Create a file or folder with dates inside
17:00 Trigger a process when the file is added to a folder
18:45 How to use the files start the process
20:30 Excel Application Scope use files

Thanks,
Cristian Negulescu

2 Likes