SharePoint - create folder if it doesn't already exist

I have created a scenario that includes creating a new folder in a SharePoint site with a name pulled from a previous module. This works fine, except when a folder with that name already exists, in which case another folder is created with a number appended at the end of the folder name.

Is there any way to check for an existing folder before creating the new folder?

@Trimergence :raised_hands:

Hi there! Iā€™m an AI that is still learning. It sounds like youā€™re trying to check if a folder already exists before creating a new one. Is that correct? If so, can you provide more information about the SharePoint site and the module youā€™re referencing?

Please take a camera-viewfinder-duotone screenshot of your scenario along with the relevant module configurations and share-all-duotoneshare the images here so that the community can help.

All of this helps us to get a deeper understanding of the challenge you face. :make:

You can achieve this use case by doing List Folders and then comparing folder name and checking if that is already available.

However, the Make SharePoint module doesnā€™t have the ā€œList foldersā€ action, so I recommend you use the Make an API Call action.

You can get the relevant API doc here to try and test the List Folders API.

1 Like

Thanks @Growwstacks.com ā€“ Iā€™m finally getting back to thisā€¦ I will take a look at the REST documentation from Microsoft and see if I can figure this out. I may be back with more questions. :wink:

@Growwstacks.com
Unfortunately, it appears trying to figure out exactly what I need to do in terms of the API call to list folders in a SharePoint document library is far enough outside of my skillset that Iā€™m going to need more help.

I figure I need to get the SharePoint site details first, then I can pull that into the API call setupā€¦ but from there Iā€™m lost.

Iā€™m also not sure how to do the ā€œif/thenā€ scenario once I do get the folder list ā€“ i.e., if exists, then upload to the existing folder, if doesnā€™t exist, create new folder then upload to the new folder.



Am I at least on the right track?
Can you provide some additional guidance?

Thanks,
Scott

I think I found a workaroundā€¦

I may be able to use the OneDrive module, and search folders in ā€œSiteā€™s Driveā€ and then choose the necessary SharePoint site and folder.

Iā€™ll still need to figure out how to do the if/then for if the folder is found or not.

It took a lot of trial and error, but the workaround works!

Thanks @Growwstacks.com ā€“ your response got me started thinking creatively.

I used a OneDrive module to search for a folder matching ā€œCompany Nameā€ from the PandaDoc document, then used a router with filters searching on whether ā€œNameā€ of the folder exists from the OneDrive output. Then either create the folder if it doesnā€™t exist and save the document, or just save the document to the folder if it already exists.

I am glad to see you found the solution yourself.

Let me know if you have any other question,

1 Like

Hello there @Trimergence welcome to the community :wave:

Awesome work figuring this out by yourself and thanks a lot for circling back to the community and sharing your solution with us. We truly appreciate that :pray:

Hey @Trimergence

I have the same issue, but OneDrive Module does not bring me the folders from SharePoint, how did you make the ā€˜One Driveā€™ Module look for folders in your ā€˜SharePointā€™?

Hi @Berry_Porgesz

The ā€œSiteā€™s Driveā€ was just there as an option. I assume this is because I had connected my work MS 365 account, so the module could see that I had both OneDrive and SharePoint as part of that work account.

In the attached screenshots you can see Iā€™m logged into a Microsoft accountā€¦ that happens to be my work account. Then you can also see that ā€œSiteā€™s Driveā€ is an option under ā€œChoose your OneDrive locationā€

Iā€™m afraid I canā€™t offer any more insight than thatā€¦ it just worked for me.

If I had to guess, Iā€™d suggest checking the MS account youā€™re using, and also check your SharePoint permissions (Iā€™m not sure what to look for, but thatā€™s what pops into my head).


1 Like

Thanks @Trimergence I got it!

Can you please share the last step configuration? uploading a file to the newly created folder?

Thank you

Sure @Berry_Porgesz ā€“ hereā€™s a screenshotā€¦ using the SharePoint ā€œUpload a fileā€ module