Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the command line to remove all files and folders except for one particular subfolder by following these steps:

  1. Open a command prompt or terminal window.

  2. Navigate to the parent directory of the subfolder you want to keep. For example, if your subfolder is located at "C:\parent\subfolder\", navigate to "C:\parent\".

  3. Type the following command and press enter:

    rmdir /S /Q directory

    Replace directory with the name of the directory you want to remove, except for your subfolder.

    For example, if you have folders named "folder1", "folder2" and "subfolder", and you want to keep "subfolder", you would run the command:

    rmdir /S /Q folder1 folder2

  4. Your computer will begin deleting all the files and folders in the specified directory, except for your subfolder.

Note: Make sure you double-check that you have specified the correct subfolder and directories you want to delete before running the command, as it cannot be undone.