Looking for assistance in searching for existing file folders

I am building a bot that must create a file folder for an individual that does not currently have a folder created. For each instance, the individual “identifier” will be a variable.

For example:
candidateName = “Smith001”

I must search through a directory to see if folder “Smith001” already exists.

Folder Path to search: C:\xxxx\xxxxxxx\xxxxxxxx\Candidate Files\N to Z\Smith001

I tried using the “Path Exists” options; however, it’s not allowing to use wildcards in the path name. I need to use the wildcards to allow for a different subfolder to be searched. (ie. A to M instead of N to Z)

I tried the following and it worked…

Folder Path to search: “C:\xxxx\xxxxxxx\xxxxxxxx\Candidate Files\N to Z”+candidateName

But in an attempt to create a wildcard for the \N to Z, I tried the following and it did not work…

Folder Path to search: “C:\xxxx\xxxxxxx\xxxxxxxx\Candidate Files\N to Z”+"*"+candidateName

How do I search for a file folder (…or a folder containing the candidateName variable) in a directory?


Welcome to forums

If i understand you correctly you have a folder with other subfolders

Now you want a folder to create before that you need to check the sub folders is contains already the folder or not

Is it this you want to do?


Please try this…SearchOption.AllDirectories will search all the subfolder under “CandidateFiles”

 Directory.getfiles("C:\xxxx\xxxxxxx\xxxxxxxx\Candidate Files\","Smith001",SearchOption.AllDirectories)

Ugh…I’m not exactly sure what you mean. Would I put this in the path location in the search folder command?

Yes…I’ll explain a bit more.

An incoming email contains a candidate’s name identifier along with a specific job they are applying. Every time an email comes in, we must create a folder using the candidate’s name identifier as the name of the folder. We then populate the folder with other job-related documents. If the given candidate already applied for a job in the past, they would already have a folder in the directory (named by their name identifier) and we would not need a new folder. In that case, we could store all the job-related documents in the folder already created.

So…if the current variable is the name identifier. I need to search the directory for this folder…if it exists, move to next step. If not, create this folder.

Hope this helps.

SearchOption.AllDirectories will browse through all the folder inside MoveFiles…in the below example…

I have three folders under MoveFiles and one of the folder has Smith001



So my above code Returned 1, you can use that code in the if condition as shown below…

Directory.GetDirectories("YourFolderPath","Smith001",SearchOption.AllDirectories).Count >= 1

Let me know , if this is what you are looking for??