Unable to detect File Location

Hi All,
I am facing this issue!
Can anyone please guide me abit on it.
Error Details: Delete: Could not find file ‘C:\Users\jasmi\OneDrive\Documents\UiPath\Generate_Yearly_Report_Performer\Data\Temp’.

Also Please have a look at the path name

1 Like

@Jasmine_Kaur_Buttar

If you want to delete a file , add file extension as well.

Cheers

Thanks Ramprasad, Can you please guide how it is possible to add file extension in this command Config(“ReportsDownloadPath”).ToString

@Jasmine_Kaur_Buttar - Let’s say if you have excel file with name temp.xlsx then you have to give pah like this C:\Users\jasmi\OneDrive\Documents\UiPath\Generate_Yearly_Report_Performer\Data\Temp.xlsx then it will work you have to change this in config file

You can do one thing you can surround Delete activity with try catch block just to avoid future exception in case bot stopped forcefully.

Hope it helps.

Best!!
Anmol

1 Like

@Jasmine_Kaur_Buttar

If you want to delete a file, first check whether the file exists or not.
IF:
File.Exists(“Your file path here with extension”)
Then
Delete

If you want to delete a Directory, first check whether the Directory exists or not.
IF
Directory.Exists(“Your Directory path here”)
Then
Delete

See the below Image :

1 Like

Fine
usually DELETE Activity will take file path with filename and file extension
but here we have mentioned till folder Temp
so we need to mention the file that we want to delete from Temp folder
–may be like this as @anmolk171 suggested
C:\Users\jasmi\OneDrive\Documents\UiPath\Generate_Yearly_Report_Performer\Data\Temp\yourfilename.fileextension

hope this would help you
and to avoid this rathher using TRY CATCH block the most advisable one is using PATH EXISTS activity so that we will come to know whether the file is there or not
–so before to this DELETE FILE activity use a PATH EXISTS Activity whhere mention the file path and get the output with a variable of type boolean named bool_fileexists
–thenn use IF condition like this
bool_fileexists = True
if true it will go to THEN Part where keep this DELETE activity

so that we wont face any issue

Cheers @Jasmine_Kaur_Buttar

1 Like

Hi @Jasmine_Kaur_Buttar if the file you want to delete can be found at this path: C:\Users\jasmi\OneDrive\Documents\UiPath\Generate_Yearly_Report_Performer\Data\Temp.xlsx

you would simply put Config(“ReportsDownloadPath”).tostring+".xlsx"

If you however want to delete everything in the Temp folder you I suggest the simplist way is:

For each - where you would specify for each time in directory.getfiles(config(“ReportsDownloadPath”).tostring)

and then use in the body a delete file where you will be deleting the item.tostring

Hi Thanks for the reply. It seems that path exists activity is unable to recognise the provided path. So what should I do!

Thats the path file, taken from the properties

I think this is what you need?

DeleteFile.xaml (5.5 KB)

In the image above my post do you have a folder called Config or are you pointing to a file and missing the extension i.e. C:\Users\jasmi\OneDrive\Documents\UiPath\Generate_Yearly_Report_Performer\Data\Config.xlsx

Should you just have

C:\Users\jasmi\OneDrive\Documents\UiPath\Generate_Yearly_Report_Performer\Data\

Instead?