Del command

by admin on November 6, 2011

On Windows computers, we can delete files from command prompt using the command Del.  Below you can find syntax of this command. This command can be used with the same syntax in batch scripts.

Delete a single file from command line:

The basic syntax of this command is as follows.

Del filename

Del command does not print anything upon the successful deletion of files. See the example below.

D:\>dir /s /b
D:\>del 1.pdf
D:\>dir /s /b

Delete multiple files from command line

We can specify multiple file names with the del command.

del filename1 filename2 filename3 filename4....


D:\>dir /s /b
1.pdf 2.pdf 3.pdf
D:\>del 1.pdf 2.pdf 3.pdf
D:\>dir /s /b

Delete all files in a directory

You can do this by specifying relative/absolute path of the directory with the del command.

del directory_path


c:\>dir /s /b data
c:\data\1.pdf  c:\data\2.pdf c:\data\3.pdf
c:\>del data
c:\data\*, Are you sure (Y/N)? y
c:\>dir /s /b data

Delete Read only files
If you run del command on a read-only file, you would get access denied error.

E:\>attrib 1.pdf
A    R       E:\1.pdf
E:\>del 1.pdf
Access is denied.

We can delete a read-only file by adding /F flag.

E:\>attrib 1.pdf
A    R       E:\1.pdf
E:\>del /F 1.pdf

Using wild cards with del command
We can use ‘*’ with del command. For example to delete all jpg files in the current directory, we can use the below command.

del *.jpg

Delete in quiet mode, skip confirmation

You can add /Q flag when you are deleting files with global wild card ‘*’ or deleting all the files in a directory.

E:\>del *
E:\*, Are you sure (Y/N)? n
E:\>del /q *

Confirm deletion for each file

When you are deleting all the files in a directory, del command would ask for confirmation only once. This way, you can say ‘yes’ either for all the files or for none of them. If you want to provide that input for each file differently, then you can add /P flag.

E:\>del /p *.pdf
E:\1.pdf, Delete (Y/N)? y
E:\2.pdf, Delete (Y/N)? n
E:\3.pdf, Delete (Y/N)? y

This command works on all Windows editions. If you have any questions feel free to write in the comments.

{ 3 comments… read them below or add one }

Michael Beijer December 15, 2013 at 12:52 am

Hi there,

How can I delete all instances of a specific file (‘Desktop.ini’) from my C:/ drive?



admin January 1, 2014 at 2:28 pm

This should work – del /S desktop.ini

I would recommend to first run the below command to check if it’s deleting the right files which you are expecting to be.
del /P /S desktop.ini

Lalitha December 2, 2014 at 5:07 am

Can anyone tell me about, how can we get pdf files using command prompt


Leave a Comment

Previous post:

Next post: