How to delete files and folders

Overview

Warning: CMD deletion normally bypasses the Recycle Bin. Back up important data and list the exact target before deleting.

del (or erase) removes files. rmdir (or rd) removes directories.

  • Preview wildcard matches with dir before passing the same pattern to del.
  • rmdir without /s removes only an empty folder.
  • Keep confirmation enabled while learning.

Commands to try

Type each command at the prompt, then press Enter. Replace sample names and paths with ones that exist on your computer.

Commands are generally not case-sensitive, but preserving the spelling shown here makes scripts easier to read.

dir old*.txt
del /p old-file.txt
rmdir EmptyFolder
rmdir /s PracticeCopy

Useful options and details

Options change how a command behaves. Add spaces exactly as shown, and use the command's built-in help when an option is unfamiliar.

A path containing spaces must be enclosed in double quotes, such as "C:\My Files".

  • del /p prompts for each file.
  • del /a:h targets hidden files; use only when intentional.
  • rmdir /s deletes a folder tree; adding /q removes confirmation and is especially dangerous.

Tips and common mistakes

Check the current folder and read the command output before assuming an operation succeeded.

Practice with disposable files first. Commands that delete, overwrite, or stop a process may not offer an Undo button.

  • Never experiment with del *, drive roots, C:\Windows, or another user's folders.
  • Quotes protect paths with spaces but do not make deletion safer.
  • Read the full expanded path; a mistaken current directory changes what a relative target means.

Safe practice

Create a temporary practice folder under your user profile so the examples cannot affect Windows system files.

After each command, inspect the result with dir or another read-only command before continuing.

  • Create a disposable file, list it, and delete it with /p.
  • Create and remove an empty disposable folder.
  • Do not use /q during practice.