Skip to content

Batch Script Deleting Files

Learn how to use the del command in Windows Batch scripts to delete files with options like /P for confirmation, /F for forced deletion, /S for subdirectories, and wildcards for bulk file removal.

Syntaxbatch
del [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names

The following are the possible options for the del command:

Name Description
Names Specifies a list of one or more files or directories. Wildcards may be used to delete multiple files. If a directory is specified, all files within the directory will be deleted
/P Prompts for confirmation before deleting each file.
/F Force deletes of read-only files.
/S Deletes specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global wildcard.
/A Selects files to delete based on attributes.
attributes R Read-only files
S System files
H Hidden files
A Files ready for archiving

Examples

The following script will delete the file test.bat in the current directory, if the file exists.

del test.bat

The following command will delete the file C:\test.bat in the current directory, if the file exists.

del c:\test.bat

The * (asterisk) character is a wildcard. *.bat indicates that you want to delete all bat files in the c:\directory.

del c:\*.bat

The ? (question mark) is a single wildcard character for a letter. Using this command in the following example will delete any file ending with est.tmp, such as best.tmp or test.tmp.

del c:\?est.tmp
Navigation