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

Glenn Maxwell 6,891 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,609 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
6,431 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,107 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,407 questions
{count} votes

Accepted answer
  1. Emily Du-MSFT 26,551 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.


4 additional answers

Sort by: Most helpful
  1. Martinez, Michael 6 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!

    1 person found this answer helpful.
    No comments

  2. Joaho DosSantos 1 Reputation point
    2021-11-01T11:39:24.483+00:00

    Solution:
    Either you disable the Hold for the site from Office 365 Security and Compliance center as Global Administrator (and allow some time to take effect!) or as the error message says, delete all files and sub-folders inside the folder first! You can use “View in File Explorer” or PowerShell too to make it easier.

    Read more: https://www.sharepointdiary.com/2018/08/fix-you-have-to-delete-all-items-in-this-folder-before-you-can-delete-folder-error-sharepoint-online.html#ixzz7AxuXgASa

    BTW @Martinez, Michael you can and you should backup files to Onedrive.

    "lousy design" was made in Dos 6.22 allowing any threat actor with unattended access to your credentials or files, to go on and delete all your files. DLP or Data Loss prevention was created to address that exact "lousy design"


  3. Conway Liu 1 Reputation point
    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.

  4. some_monkey 1 Reputation point
    2022-08-10T13:06:47.37+00:00

    NO NEED FOR ANYTHING COMPLICATED

    Simply go into to the sharepoint folder you wish to delete in a browser.
    In the top left click the checkbox that selects all folders.
    Click delete. It will take some time to delete all folders.
    Back out one directory level. Delete the folder.
    Done