How to check file exists in folder or not

Hello Friends,

In folder i have .xls file like below
TASK_todaydate_int valuve

e.g.

  1. TASK_20230329_071623830
  2. TASK_20230328_07233067

I wanted to check file exists or not…i am using path exists active…how to ignore int value while check ?

Hi @Bot_Learner

You can use the following activity:

image

Hope this helps,
Best Regards.

@Bot_Learner
PartialFileName = “TASK_20230329”
If item.ToString.Contains(PartialFileName)
Regards

Hi @Bot_Learner ,

Considering that you would want to find if today’s date file is present or not irrespective of the number values after it, Maybe we would need to switch to the below Expression and apply it directly in an If activity :

Directory.GetFiles("YourFolderPath","TASK_"+Now.ToString("yyyyMMdd")+"_*").Any

Let us know if you are still having issues in resolving this.

1 Like

Hi @Bot_Learner ,

Use the following to get the files using your desired pattern, and use the if condition based on if the count is greater than 0:

Directory.GetFiles(“FolderPath”,“TASK_”+now.tostring(“yyyyMMdd”)+“_*.xls”).Count

1 Like

Hello @vishal.kp for .count error: Cannot assign from type System.Int32 to type System.String in assign activity Assign

@Bot_Learner , if your assigning it to an array of string you can remove the count function

Directory.GetFiles(“FolderPath”,“TASK_”+now.tostring(“yyyyMMdd”)+“_*.xls”)

For getting the first file path from the array:

Directory.GetFiles(“FolderPath”,“TASK_”+now.tostring(“yyyyMMdd”)+“_*.xls”).First

Hello @supermanPunch for .Any error: Cannot assign from type System.boolean to type System.String in Assign activity Assign

Variable in to is type of System.string

Hello @vishal.kp thanks, then how to check in condition in next activity like if or path exits …to verify file exist

Just like how @supermanPunch has mentioned .any function will give you boolean value. Using that, you can determine if it exists.

1 Like