How to check file name exists in the path by using file Name from Excel?

How to check file name exists in the path by using file Name from Excel?
I have excel file with

How can RPA check file name in path (column A) contain with report name from column B?
I use “Path exits”,it’s always return False

@mhon How are you using Path Exists? Is there a File name AAA in the Path C:/user/Documnet ?

Under For each row
@ Path Exists
Input Path =“c:/user/Document” + row.“ReportName”.Tostring + “.
Path Type = File
Output Exists = vExists

in path c:/user/Document , There is file AAA.999.TXT . I need value “vExists” return = True but it’s always False.


Hope the following expression helps you.

vExist = System.IO.Directory.GetFiles("c:/user/Document","*.*").Any(Function(x) x.Contains(row("ReportName").ToString()))



@mhon -
Check the PathExists activity - file path should be complete path along with the file extension.
Ex: C:/user/Document/AAA.txt

Create a filePath variable and Assign value like dtFilesRow(“Path”).ToString.Trim + “/” + dtFilesRow(“ReportName”).ToString.Trim and use the variable to PathExists activity.

Hi @mhon u are missing a “/” after “c:/user/Document”

1 Like

Your answer is work!!!
vExists is return True.
Many thanks a lot.

1 Like


Great to hear that. FYI, if there is a possibility there is search keyword in your path, the following expressions might be better.

vExist = System.IO.Directory.GetFiles("c:/user/Document","*.*").Any(Function(x) System.IO.Path.GetFileName(x).Contains(row("ReportName").ToString()))

If you want to check only filename without extension, the following will work.

vExist = System.IO.Directory.GetFiles("c:/user/Document","*.*").Any(Function(x) System.IO.Path.GetFileNameWithoutExtension(x).Contains(row("ReportName").ToString()))



Thank you for your kindly!!!
May I ask you again?
Is it possible to get the exactly name of file?

example, I use “AAA” as report name to find in path “c:/user/document/” For your suggestion vExists is return “True” . The next step I want to copy that file AAA.999.TXT to another floder.
How can I get the “AAA.999.TXT” ?

Sorry,For my question I am a beginner in this area.


If you want to get the full file name, the following expression helps you.

arrFile = System.IO.Directory.GetFiles("c:/user/Document","*.*").Where(function(x) System.IO.Path.GetFileName(x).Contains(row("ReportName").toString)).ToArray

To check its existance, we can check with the array length.

If arrFile.Length equals 1, arrFile(0) is what you want.
If arrFile.Length equals 0, there is no file.



Many Thanks for your help. It’s work!!!
:+1: :+1: :+1:

@mhon, I know it works for you but you may want to consider File.Exists() method to simplify your code.

Step 1: fileName = row(“Path”) + “/” + row(“ReportName”)
Step 2: If File.Exists(fileName).

It will return Boolean value.

Thank you for your simple answer.
But I don’t know the exactly name of file in path(c:/user/document/") , just need to check only that file name contain with “AAA” or not.


Cool :+1: