Recursively

How to delete folder with subfolders using command line on Windows 10

It's possible to delete a folder with subfolders and files with Command Prompt and PowerShell, and here's how.

Recursively delete folders commands

You can delete a folder with subfolders and files using commands, but you need to know the correct tool that will do the job. On Windows 10, when you need to remove a file or folder with a command terminal, the first tool it comes to mind is the del command, but you will quickly find out that it won’t work to delete folders and subfolders because the tool is only meant to deal with files.

If you want to delete folders with content, the command-line tool will depend on the terminal you are using. If you are using Command Prompt, rmdir (remove directory) is the tool you want to use. On the other hand, if you are using PowerShell, the Remove-Item is the cmdlet you want to use.

In this guide, you will learn two different ways to quickly delete folders with subfolders with Command Prompt and PowerShell.

Delete folders with subfolders with Command Prompt

To delete a folder with subfolders with a command, use these steps:

  1. Open Start on Windows 10.

  2. Search for Command Prompt, right-click the top result, and select the Run as administrator option.

  3. Type the following command to delete an empty folder and press Enter:

    rmdir PATH\TO\FOLDER-NAME

    In the command, replace PATH\TO\FOLDER-NAME with the folder path and the folder name of the folder you want to delete.

    This example removes the “files” folder:

    rmdir C:\files

    Delete empty folder
    Delete empty folder
  4. Type the following command to delete folder and subfolders with contents and press Enter:

    rmdir /s PATH\TO\FOLDER-NAME

    This example removes the “files” folder, subfolders, and files:

    rmdir /s C:\files

    Delete folder with content
    Delete folder with content
  5. Type the following command to delete a folder with content recursively without confirmation prompt and press Enter/p>

    rmdir /s /q PATH\TO\FOLDER-NAME

    This example removes the “files” folder, subfolders, and files without prompting for confirmation:

    rmdir /s /q C:\files

    Delete folder with subfolders quietly
    Delete folder with subfolders quietly

Once you complete the steps, the folder and its contents will be deleted from Windows 10.

The /s option deletes the folder and its content in the above command, but it prompts the user for confirmation. The /q option ignores the prompt and deletes the folder recursively.

Delete folders with subfolders with PowerShell

To recursively delete an entire folder with a PowerShell command, use these steps:

  1. Open Start.

  2. Search for PowerShell, right-click the top result, and select the Run as administrator option.

  3. Type the following command to delete an empty folder and press Enter:

    Remove-Item PATH\TO\FOLDER-NAME

    In the command, replace PATH\TO\FOLDER-NAME with the folder path and the folder name of the folder you want to delete.

    This example removes the “files” folder:

    Remove-Item C:\files

    PowerShell delete folder command with confirmation
    PowerShell delete folder command with confirmation
  4. Type the following command to delete an empty folder and press Enter:

    Remove-Item -Recurse -Force PATH\TO\FOLDER-NAME

    This example removes the “files” folder:

    Remove-Item -Recurse -Force C:\files

    PowerShell recursively delete folder
    PowerShell recursively delete a folder

After you complete the steps, the folder, subfolders, and files will be removed from the computer with or without a prompt, depending on the command you used.

The -Recurse option tells the command that you want to delete the folder and its contents without prompt confirmation. The -Force option is not required, but it allows to erase of special items, including read-only or hidden files.