Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Delete Files & Folders via CMD on Windows 10

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Deleting files and folders using Command Prompt on Windows 10 is a fast, scriptable alternative to the graphical interface. It lets you remove stubborn items, handle batch deletions, and bypass some Explorer restrictions. You don't need any special tools—just a normal user account (admin rights are only required for certain system locations). This guide walks you through the essential commands, common pitfalls, and fixes.

What You'll Need

  • A Windows 10 PC with Command Prompt available (it's built-in).
  • Basic knowledge of file paths (e.g., C:\Users\YourName\Documents).
  • Administrator privileges if you plan to delete files in protected system folders (like C:\Windows).

Step-by-Step

  1. Open Command Prompt. Press Win + R, type cmd, and press Enter. For admin rights, press Ctrl + Shift + Enter instead.
  2. Navigate to the parent folder (optional). Use the cd command to change directories. For example, to go to your Documents folder, type cd C:\Users\YourName\Documents and press Enter. You can skip this if you'll use full paths.
  3. Delete a single file. Type del "filename.ext" and press Enter. For example: del "report.txt". If the file is in another folder, use the full path: del "C:\Users\YourName\Desktop\old.txt".
  4. Delete multiple files at once. Use wildcards. For instance, del *.log deletes all .log files in the current directory. Be careful—this is permanent.
  5. Delete an empty folder. Use rmdir "foldername" (or the short form rd). Example: rmdir "OldFolder". This only works if the folder is completely empty.
  6. Delete a folder and all its contents. Use rmdir /s "foldername". The /s flag removes the folder, its subfolders, and all files. You'll be prompted to confirm; type Y and press Enter. To skip the prompt, add /q: rmdir /s /q "foldername".
  7. Delete files with specific attributes. If a file is read-only or hidden, add /f to force deletion: del /f "file.txt". For hidden files, you might need /a:h to target them: del /a:h "hidden.txt".
  8. Verify deletion. Use dir to list the directory contents and confirm the items are gone.

Common Mistakes

  • Forgetting quotes around paths with spaces. If your folder name has spaces (e.g., My Files), you must enclose the entire path in double quotes, otherwise the command treats it as multiple arguments.
  • Using del on a folder. The del command only works on files. For folders, you must use rmdir (or rd).
  • Not using /s with rmdir on a non-empty folder. You'll get an error: The directory is not empty. Add /s to delete the entire tree.
  • Deleting from the wrong directory. If you're not sure where you are, run cd without arguments to display the current path. Or use pwd (works in newer Windows).
  • Being too broad with wildcards. del *.* deletes every file in the current folder—that's often not what you want. Double-check the pattern before pressing Enter.

Tips

  • Use full paths to avoid mistakes. Instead of navigating with cd, you can directly specify the full path in the command, e.g., del "D:\Backup\old.zip".
  • Add /q to quiet the confirmation. When deleting multiple files or folders, adding /q suppresses the 'Are you sure?' prompt, speeding up batch operations.
  • Test with echo first. Before deleting a large batch, list what will be deleted with dir /s /b "pattern" to see the exact files.
  • Use del /s to delete files in subfolders. This will search recursively and delete matching files in all subdirectories. Combine with /q to avoid prompts.
  • Create a backup before mass deletions. If you're unsure, move the files to a temporary folder instead of deleting them permanently.

Troubleshooting

  • "Access is denied" error. This usually means the file or folder is in use, or you lack permissions. Close any programs that might be using the file, or run Command Prompt as Administrator.
  • "The file is being used by another process." Identify the process (like a text editor or media player) and close it. If it's a system process, you may need to restart your PC and try again.
  • "Cannot find the specified file." Double-check the path and spelling. Use dir to list files in the directory to confirm the exact name.
  • File is read-only. Use del /f to force deletion, or remove the read-only attribute first with attrib -r "file.txt".
  • Folder is not empty but you want to keep it. Delete the contents individually with del /s /q "foldername\*", then remove the empty folder with rmdir "foldername".
  • Command prompt closes immediately. If you're running a batch script, add pause at the end to keep the window open and read any error messages.

Frequently Asked Questions

Can I undo a deletion made in Command Prompt?

No, the del and rmdir commands permanently remove files and folders—they do not go to the Recycle Bin. There's no built-in undo. Always double-check your command before executing.

How do I delete all files in a folder but keep the folder itself?

Use del /s /q "C:\path\to\folder\*". This deletes all files and subfolders' contents, but leaves the top-level folder intact. Be cautious—this is irreversible.

What is the difference between del and rmdir?

del is for deleting files only. rmdir (or rd) is for removing empty directories. To delete a folder with its contents, use rmdir /s.

Why does rmdir say "The directory is not empty" even though I see no files?

There might be hidden or system files. Use dir /a to show all files including hidden ones. Then delete them individually or use rmdir /s to force removal.

Can I delete files from a network drive using CMD?

Yes, if the drive is mapped to a letter (e.g., Z:), you can use the same commands with that path. If it's an UNC path (like \\server\share), you may need to use pushd first to map it temporarily.

Is it safe to use wildcards like *.*?

It's safe only if you're absolutely certain of the files you're targeting. *.* matches every file in the directory, which can lead to accidental mass deletion. Always list the files first with dir.