- Batch Script Tutorial
- Batch Script - Home
- Batch Script - Overview
- Batch Script - Environment
- Batch Script - Commands
- Batch Script - Files
- Batch Script - Syntax
- Batch Script - Variables
- Batch Script - Comments
- Batch Script - Strings
- Batch Script - Arrays
- Batch Script - Decision Making
- Batch Script - Operators
- Batch Script - DATE & TIME
- Batch Script - Input / Output
- Batch Script - Return Code
- Batch Script - Functions
- Batch Script - Process
- Batch Script - Aliases
- Batch Script - Devices
- Batch Script - Registry
- Batch Script - Network
- Batch Script - Printing
- Batch Script - Debugging
- Batch Script - Logging
- Batch Script Resources
- Batch Script - Quick Guide
- Batch Script - Useful Resources
- Batch Script - Discussion
Batch Script - Deleting Files
For deleting files, Batch Script provides the DEL command.
Syntax
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
Following are the description of the options which can be presented to the DEL command.
S.No. | Options & Description |
---|---|
1. |
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 |
2. |
/P Prompts for confirmation before deleting each file. |
3. |
/F Force deletes of read-only files. |
4. |
/S Deletes specified files from all subdirectories. |
5. |
/Q Quiet mode, do not ask if ok to delete on global wildcard. |
6. |
/A Selects files to delete based on attributes. |
7. |
attributes R Read-only files, S System files, H Hidden files, A Files ready for archiving - Prefix meaning not |
Following examples show how the DEL command can be used.
Examples
del test.bat
The above command will delete the file test.bat in the current directory, if the file exists.
del c:\test.bat
The above command will delete the file C:\test.bat in the current directory, if the file exists.
del c:\*.bat
The * (asterisks) is a wild character. *.bat indicates that you would like to delete all bat files in the c:\directory.
del c:\?est.tmp
The ? (question mark) is a single wild character for one letter. The use of this command in the above example will delete any file ending with "est.tmp", such as pest.tmp or test.tmp.