Skip to main content

Batch Script Deleting Files

Deleting Files

In Batch Script, you can delete files with the del command.

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

The following are the possible options for the del command:

NameDescription
NamesSpecifies 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
/PPrompts for confirmation before deleting each file.
/FForce deletes of read-only files.
/SDeletes specified files from all subdirectories.
/QQuiet mode, do not ask if ok to delete on global wildcard.
/ASelects files to delete based on attributes.
attributesR 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

Table of Contents