Sharepoint : Trying to create a reusable workflow for sharepoint to check if a folder exist or not and based on result return True Or False

Hi Devs,

I am trying to create a reusable workflow for SharePoint to check if a folder exist or not and based on result return True Or False.

If anyone has any idea how to do it please let me know.

Many thanks in advance.

hi @Eshu_Dhiman,

Recommended reusable approach:

  • Use Find Files and Folders (SharePoint)
  • Pass the parent folder path
  • Filter by the folder name
  • If the result contains the folder → return True
  • If no result → return False

Expose Site URL and Folder Path as inputs and return a Boolean output.

Can you please share the screenshot where I can find this.

As per my understanding this is deprecated.

Thankyou for replying

You’re correct. Find Files and Folders (SharePoint) doesn’t appear in all environments even with the M365 package installed.
A reliable alternative is Get Files and Folders, then check if the folder exists in the result set.

you can also use linq for this:

System.IO.Directory.GetFiles(folderPath, fileName).Any()

  • Returns True → file exists
  • Returns False → file does not exist

Can you elaborate, I the answers you are posting here is coming from Chat GPT or Claude.

Because it recommended the same steps.

I need to know if any one has created a robust solution for this problem.

:laughing:

This is regarding sharepoint. Lol have you created an agent to post replies via LLMS on forum? Interesting :sweat_smile: :rofl:

test if it works have you tried this? System.IO.Directory.GetFiles(folderPath, fileName).Any()

For SharePoint, Directory.GetFiles works only if the document library is mapped as a local drive. Otherwise, SharePoint activities should be used.

I have to use sharepoint activities .

Then you can go with Get Files and Folders (SharePoint). Test this activity to return boolean.

@Eshu_Dhiman

it can be done in two steps

first get file/folder list (Use with relative path, return only 1 item, and only folder option)

then use if condition to check if anything is returned. If returned folder exists, if not use create folder

cheers

Hi what if the path i am searching for is not there.

1 Like

Can you share a workflow with me for better understanding

1 Like

@Eshu_Dhiman

If the path does not exist the returned variable will be nothing or empty..so that is what you would check in if condition ..if its nothing you will create else you can proceed as path already exists

Sample

Also I believe with new activity with a single activity also it might be done I guess it has a dont replace option..so it either creates or moves forward.please try the same

cheers

1 Like

Hi @Eshu_Dhiman

You can make a reusable workflow with input arguments for site URL and folder path, and one Boolean output. Use a SharePoint Get Folder / Get Folder Metadata activity inside a Try Catch. If the activity succeeds, return True; if it throws an exception, catch it and return False. This keeps it simple and reusable across folders.

Hi @Anil_G , thanks for replying.

This can work for me.

The only question I have is that can we auth with client secret and application ID in modern 365 activates like we use to do it in classic?

Thanks again.

1 Like

@Eshu_Dhiman

Yes it is supported

Cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.