Delete Files & Folders via CMD on Windows 10
In this article
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
- Open Command Prompt. Press Win + R, type
cmd, and press Enter. For admin rights, press Ctrl + Shift + Enter instead. - Navigate to the parent folder (optional). Use the
cdcommand to change directories. For example, to go to your Documents folder, typecd C:\Users\YourName\Documentsand press Enter. You can skip this if you'll use full paths. - 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". - Delete multiple files at once. Use wildcards. For instance,
del *.logdeletes all.logfiles in the current directory. Be careful—this is permanent. - Delete an empty folder. Use
rmdir "foldername"(or the short formrd). Example:rmdir "OldFolder". This only works if the folder is completely empty. - Delete a folder and all its contents. Use
rmdir /s "foldername". The/sflag removes the folder, its subfolders, and all files. You'll be prompted to confirm; typeYand press Enter. To skip the prompt, add/q:rmdir /s /q "foldername". - Delete files with specific attributes. If a file is read-only or hidden, add
/fto force deletion:del /f "file.txt". For hidden files, you might need/a:hto target them:del /a:h "hidden.txt". - Verify deletion. Use
dirto 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
delon a folder. Thedelcommand only works on files. For folders, you must usermdir(orrd). - Not using
/swithrmdiron a non-empty folder. You'll get an error: The directory is not empty. Add/sto delete the entire tree. - Deleting from the wrong directory. If you're not sure where you are, run
cdwithout arguments to display the current path. Or usepwd(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
/qto quiet the confirmation. When deleting multiple files or folders, adding/qsuppresses the 'Are you sure?' prompt, speeding up batch operations. - Test with
echofirst. Before deleting a large batch, list what will be deleted withdir /s /b "pattern"to see the exact files. - Use
del /sto delete files in subfolders. This will search recursively and delete matching files in all subdirectories. Combine with/qto 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
dirto list files in the directory to confirm the exact name. - File is read-only. Use
del /fto force deletion, or remove the read-only attribute first withattrib -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 withrmdir "foldername". - Command prompt closes immediately. If you're running a batch script, add
pauseat 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.