Bulk create folders in document library

Brass Contributor

I have a document library with a folder that represents every state in the United States.  Within each folder, I need to create a folder for each one of our theaters.  Within each theater folder needs to be the same additional folders and even more folders within those folders.

 

I found a video saying to user Power Apps to create a flow to bulk create the folders but I wanted to see if anyone knows of any other way?  Is there a way to import an Excel document with all of the folder structure in place?  Thanks in advance!

1 Reply

Hi @Beth_Culpepper,

you can try to do this by using PowerShell:

  1. Prepare an Excel file with the following columns:
    • State
    • Theater
    • AdditionalFolder
    • Subfolder1
    • Subfolder2
  2. Save the Excel file to your local computer.
  3. Open a PowerShell console and connect to your SharePoint site.
  4. Run the following PowerShell script:
 

 

# Import the CSV file
$CSVFile = Import-Csv "C:\Path\To\CSVFile.csv"

# Get the document library
$Library = Get-PnPList -Identity "DocumentLibraryName"

# Create each folder in the document library
ForEach($Row in $CSVFile) {
    $FolderURL = $Library.RootFolder.ServerRelativeUrl + "/" + $Row.State + "/" + $Row.Theater + "/" + $Row.AdditionalFolder + "/" + $Row.Subfolder1 + "/" + $Row.Subfolder2
    Resolve-PnPFolder -SiteRelativePath $FolderURL | Out-Null
}

 

  1. Replace C:\Path\To\CSVFile.csv with the path to your CSV file.
  2. Replace DocumentLibraryName with the name of your document library.
  3. Run the script.


Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.


If the post was useful in other ways, please consider giving it Like.


Kindest regards,


Leon Pavesic
(LinkedIn)