You have to delete all the items in this folder before you can delete the folder.

Glenn Maxwell 8,416 Reputation points
2021-06-22T10:55:40.2+00:00

Hi All

i have a folder in team site. When i am trying to delete the folder i am getting the below error.

You have to delete all the items in this folder before you can delete the folder.

Documents->Test1->Test2
I am trying to delete Test2 folder and the folder is empty it doesn't have any files or folders in it. Please help me

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
1,965 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,030 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
3,683 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,626 questions
{count} vote

Accepted answer
  1. Emily Du-MSFT 34,106 Reputation points Microsoft Vendor
    2021-06-23T09:38:04.133+00:00

    @Glenn Maxwell

    Whether this issue occurs in a specific folder, a specific library or a specific site collection?

    Whether the folder has unique permission? Have you enabled versioning and approval in the library?

    1.Go to library settings -> Manage files which have no checked in version -> Make sure all files are checked in.
    2.Go to Microsoft 365 admin center -> Security -> Policies -> Retention.
    3.Try to delete folder by using PowerShell.

    #Config Variables  
    $SiteURL = "https://tenant.sharepoint.com/sites/emilytest"  
    $ListName ="Branding"  
    $FolderServerRelativeURL = "/sites/emilytest /doc/test"  
    
    Try {  
        #Connect to PnP Online  
        Connect-PnPOnline -Url $SiteURL -UseWebLogin  
    
        #Get All Items from Folder in Batch  
        $ListItems = Get-PnPListItem -List $ListName -FolderServerRelativeUrl $FolderServerRelativeURL -PageSize 2000 | Sort-Object ID -Descending  
    
        #Powershell to delete all files from folder  
        ForEach ($Item in $ListItems)  
        {  
            Remove-PnPListItem -List $ListName -Identity $Item.Id -Recycle -Force  
            Write-host "Removed File:"$Item.FieldValues.FileRef  
        }  
    }  
    Catch {  
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red  
    }  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

8 additional answers

Sort by: Most helpful
  1. Martinez, Michael 26 Reputation points
    2021-10-29T14:24:44.76+00:00

    This is a common issue. One Drive does little good if we can't delete subfolders without having to delete everything below it, one at a time, first. When will this be fixed?

    I can't back up server files to One Drive if I can't use them properly. Since Dos 6.22 I've been able to delete subfolders. Having me spend hours deleting files one by one is a lousy design.

    Give us the ability in One Drive for Business to actually delete subfolders without having to delete every single file underneath it first!

    5 people found this answer helpful.

  2. Mike P 10 Reputation points
    2023-03-24T10:30:41.63+00:00

    When you have dozens of nested folders with contents. Then this becomes a nightmare to resolve.

    Please can a better solution be provided or fix the issue.

    Thanks

    2 people found this answer helpful.
    0 comments No comments

  3. Conway Liu 6 Reputation points
    2022-03-28T10:38:55.777+00:00

    Just hit this issue and found the quickest way to delete is to sync the document library to OneDrive on your local computer, then in OneDrive you can delete the top level folder and this will cause SharePoint to automatically delete from the lowest level items and folders, and work its way up to the top folder.

    1 person found this answer helpful.
    0 comments No comments

  4. veesee 5 Reputation points
    2023-03-27T22:46:54.0266667+00:00

    I click the option to "Add shortcut to OneDrive".

    Then in your Windows Explorer navigate to your OneDrive files and find the top-level folder to delete. I find that this will delete everything nested underneath.

    You may need to install the OneDrive desktop app first.

    1 person found this answer helpful.