web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Convert Document Sets ...
Power Automate
Answered

Convert Document Sets to Folders

(1) ShareShare
ReportReport
Posted on by 142
Looking for some advice/direction on how to possibly build a flow that would cycle through a document library looking for instances of a specific Document Set folder. If found, convert it to a normal folder. If it can't be converted then would need the flow to rename the DS, create a new folder with the original name of the DS, then move all content from the DS into the new folder.
 
I have several doc libraries that have over 200 top level DS's and in them there may be another DS. It is the 2nd DS I am trying to search for and update. Can do this manually but thought perhaps there was a way to automate the process.
 
Thanks
Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at
     
    You can automate this but may take some trial and error to identify the right logic to filter the document sets that need to be updated. Below is how you can start:
     
    Create a new flow and add the action -> Get Files (Properties Only) and select the Include Nested Items to true. Run the flow once and check the output of the action. Identify one of the document sets and you will be able to extract the content type ID from the output. In the flow now, add a filter array action and filter on the content type id and additional criteria that you have for identifying specific document sets that you want to update. From the filter array outputs, you can then add an action to update file properties and add the content type for a folder or list files from the document set, create a new folder and then add the files to the new folder. 
     
     
    Hope this Helps!
     
    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
  • Suggested answer
    Riyaz_riz11 Profile Picture
    4,150 Super User 2026 Season 1 on at
    Hi,

    Step 1: Initialize Variables

    Actions:
    1. Initialize variable - SiteURL (String)
    2. Initialize variable - LibraryNames (Array) 
    3. Initialize variable - TargetDSContentType (String): "Document Set"
    4. Initialize variable - ProcessedCount (Integer): 0
    5. Initialize variable - ErrorLog (Array)
    6. Initialize variable - SuccessLog (Array)
    7. Initialize variable - CurrentLibrary (String)

    Step 2: Process Each Library

    Apply to each - LibraryNames:
      Set variable - CurrentLibrary: @{item()}
      
      Get files (properties only):
        - Site Address: variables('SiteURL')
        - Library Name: variables('CurrentLibrary')
        - Folder: / (root)
        - Include Nested Items: Yes
        - Limit: 5000
        
      Apply to each - Files:
        Condition - Check if Document Set:
          @equals(item()?['ContentType'], variables('TargetDSContentType'))
          
          If Yes:
            - Call Child Flow: "Process Document Set"
            - Pass Parameters: SiteURL, LibraryName, ItemPath, ItemName

    Flow 2: Process Document Set (Child Flow)

    Input Parameters:

    • SiteURL (String)

    • LibraryName (String)

    • ItemPath (String)

    • ItemName (String)

    •  

    Flow Logic:

    Step 1: Try Direct Conversion

    Actions:
    1. Initialize variable - ConversionSuccess (Boolean): false
    2. Initialize variable - OriginalDSPath (String): @{parameters('ItemPath')}
    3. Initialize variable - OriginalDSName (String): @{parameters('ItemName')}
    
    Try Block:
      Update file properties:
        - Site Address: parameters('SiteURL')
        - Library Name: parameters('LibraryName') 
        - Id: triggerOutputs()?['body/ID']
        - Content Type: "Folder"
        
      Set variable - ConversionSuccess: true
      
      Append to array - SuccessLog:
        - Message: "Direct conversion successful"
        - Item: @{parameters('ItemName')}
        - Library: @{parameters('LibraryName')}
        - Timestamp: @{utcNow()}
    
    Catch Block:
      Set variable - ConversionSuccess: false

    Step 2: Fallback Method (If Direct Conversion Fails)

    Condition - Check ConversionSuccess:
      If No (false):
        
        # Step 2a: Get all items in Document Set
        Get files (properties only):
          - Site Address: parameters('SiteURL')
          - Library Name: parameters('LibraryName')
          - Folder: @{parameters('ItemPath')}
          - Include Nested Items: Yes
        
        # Step 2b: Rename Document Set
        Update file properties:
          - Site Address: parameters('SiteURL')
          - Library Name: parameters('LibraryName')
          - Id: [Document Set ID]
          - Name: @{concat(parameters('ItemName'), '_OLD_DS')}
        
        # Step 2c: Create New Folder
        Create new folder:
          - Site Address: parameters('SiteURL')
          - Library Name: parameters('LibraryName')
          - Folder Path: @{parameters('ItemPath')}
          - Name: @{parameters('ItemName')}
        
        # Step 2d: Move All Content
        Apply to each - Items in Document Set:
          Condition - Skip if it's the Document Set itself:
            @not(equals(item()?['ContentType'], 'Document Set'))
            
            If Yes:
              Copy file:
                - Source Site: parameters('SiteURL')
                - Source Library: parameters('LibraryName')
                - Source File: @{item()?['Path']}
                - Destination Site: parameters('SiteURL')
                - Destination Library: parameters('LibraryName')
                - Destination Folder: @{concat(parameters('ItemPath'), '/', parameters('ItemName'))}
                - Overwrite: Yes
              
              Delete file:
                - Site Address: parameters('SiteURL')
                - Library Name: parameters('LibraryName')
                - File: @{item()?['Path']}
        
        # Step 2e: Delete Old Document Set
        Delete file:
          - Site Address: parameters('SiteURL')
          - Library Name: parameters('LibraryName')
          - File: @{concat(parameters('ItemPath'), '/', parameters('ItemName'), '_OLD_DS')}
        
        # Step 2f: Log Success
        Append to array - SuccessLog:
          - Message: "Fallback conversion successful"
          - Item: @{parameters('ItemName')}
          - Library: @{parameters('LibraryName')}
          - Method: "Rename and Move"
          - Timestamp: @{utcNow()}

    Flow 3: Advanced Nested Document Set Handler

    For handling nested Document Sets specifically:

    Flow Name: "Nested Document Set Processor"
    
    Trigger: Manual or Scheduled
    
    Actions:
    1. Initialize Variables:
       - ProcessingQueue: []
       - CurrentDepth: 0
       - MaxDepth: 5
    
    2. Get All Items with Hierarchy:
       Get files (properties only):
         - Include Nested Items: Yes
         - Filter: ContentType eq 'Document Set'
         - Select: Id, Name, Path, ContentType, ParentPath
       
    3. Build Processing Queue:
       Apply to each - Document Sets:
         Compose - Depth Calculation:
           @length(split(item()?['Path'], '/'))
         
         Append to array - ProcessingQueue:
           - Id: @{item()?['Id']}
           - Name: @{item()?['Name']}
           - Path: @{item()?['Path']}
           - Depth: @{outputs('Compose_-_Depth_Calculation')}
           - ParentPath: @{item()?['ParentPath']}
    
    4. Sort by Depth (Deepest First):
       # Process deepest Document Sets first to avoid conflicts
       
    5. Process Queue:
       Apply to each - Sorted Items:
         # Call Document Set Processor Flow
         # Pass item details as parameters

    Flow 4: Monitoring and Reporting Flow

    Flow Name: "Document Set Conversion Monitor"
    
    Trigger: When main flow completes
    
    Actions:
    1. Create Summary Report:
       Compose - Report:
         - Total Libraries Processed: @{length(variables('LibraryNames'))}
         - Total Document Sets Found: @{variables('ProcessedCount')}
         - Successful Conversions: @{length(variables('SuccessLog'))}
         - Failed Conversions: @{length(variables('ErrorLog'))}
         - Processing Time: @{formatDateTime(utcNow(), 'yyyy-MM-dd HH:mm:ss')}
    
    2. Send Email Report:
       Send an email (V2):
         - To: [Admin email]
         - Subject: "Document Set Conversion Report"
         - Body: @{outputs('Compose_-_Report')}
         - Attachments: 
           - Success Log (JSON)
           - Error Log (JSON)
    
    3. Log to SharePoint List:
       Create item:
         - Site: [Monitoring Site]
         - List: "DS Conversion Log"
         - Title: "Conversion Run - @{utcNow()}"
         - Summary: @{outputs('Compose_-_Report')}
         - SuccessCount: @{length(variables('SuccessLog'))}
         - ErrorCount: @{length(variables('ErrorLog'))}
     
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz
  • Verified answer
    emberkrumwied Profile Picture
    142 on at
    @Riyaz_riz11, WOW! I really appreciate the time you took to put that altogether. I think it is beyond my skill level to implement and would probably take longer, or just as long, as if I just manually update my locations. But I do sincerely appreciate your assistance.
     
    @yashag2255, thank you as well for your response. I think I understand the basics you are proposing, but one of my issues is that the document library only has 1 document set content type. That type, and DS, is what is used to create the top level "folders". What happened is that additional DS were added inside the parent DS. So filtering for a specific CT would return all the folders when I just need to locate the "2nd" level DS.
     
    Thinking that it would probably just be faster to just manually make these changes.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 791

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 535

Last 30 days Overall leaderboard