IF Condition question


#1

Hi,

I am using the following if condition statement but it’s not working:

FiletoDelete = “\Xlsx\results.xlsx”

IF

If anyone can help that will be great.
Thanks,
Mido


#2

You can use the below condition

If “C:Users\alotfy\Documents\UiPath\Excel\Xlsx\result.xlsx”.contains(FiletoDelete)


#3

Hi @alotfy

I think it’s a problem of relative and absolute path, meaning that you need to change the condition to
FiletoDelete = “\Xlsx\results.xlsx”, it’s a maybe I don’t know what you’re assiging to FileToDelete string.

just to prove that there is nothing wrong with your condition here is a workflow to prove it:

Main.xaml (6.1 KB)

enjoy :slight_smile:


#4

Hi Reda,
When I run your script I got the message “It’s there” but the file wasn’t there.
Here is my XAML file, if you can help that will be great.
ThanksIf condition.xaml (6.0 KB)


#5

Hi @alotfy,

Looks like your requirement is to check if the file exist or not. In that case, please use the “Path Existsactivity and pass you file path and your output variable would be a Boolean value.

Use the boolean variable in the if condition

Happy Automating!


#6

Well since we assigned a value to a variable it’s going to be equal to itself so it’s going to give us true ===> it’s there
I assumed that you assign this variable in the entire worflow based on another condition that checks if the file is there or not.

If this is not the case then we will do as @PD2 described we will use Path Exists activity to check if the file is there.

So you need to do something like this : If condition.xaml (7.8 KB)

Hope it solves the problem

There is another activity File Exists but this will need the FTP dependency but the first one come by default.


#7

Thank you Reda, PD2 and vivek_Nalashaa for your help. It looks good.