Learn how to use
del command for deleting files from command prompt/CMD. This command works for read-only files and supports wildcards too.
Run del command with the name of the file to be deleted, you are done!
You do not see message after running the command if the file is deleted successfully. Error message is shown only when something goes wrong.
Delete Read only files
We can’t delete a read-only file using simple‘del’ command. We get access denied error in this scenario.
c:\>attrib readonlyfile.txt A R C:\readonlyfile.txt c:\>del readonlyfile.txt c:\readonlyfile.txt Access is denied. c:\>
del /F to delete a read only file.
del /F readonlyfile.txt
Alternatively, you can use
del /A too
del /A:R readonlyfile.txt
Delete files in bulk
Del command recognizes wildcard(*) and so can be used to delete files in bulk from CMD. Some examples below.
To delete all the files in current folder
To delete all the files with ‘log’ extension
Delete all files having the prefix ‘abc’
Delete all files having ‘PIC’ somewhere in the file name.
The above are the basic use cases of del command. Continue to read below for non trivial use cases.
Add multiple file name in the command
‘Del’ command can accept multiple files as argument
del filename1 filename2 filename3 filename4....
D:\>dir /s /b 1.pdf 2.pdf 3.pdf D:\>del 1.pdf 2.pdf 3.pdf D:\> D:\>dir /s /b D:\>