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 @manish_mandot – 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:

@manish_mandot
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 @manish_mandot – 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