|
|
|
DEL
Delete one or more files.
syntax
DEL [options] [/A:file_attributes] files_to_delete
key
files_to_delete : This may be a filename, a list of files or a Wildcard
options
/P Give a Yes/No Prompt before deleting.
/F Ignore read-only setting and delete anyway (FORCE)
/S Delete from all Subfolders (DELTREE)
/Q Quiet mode, do not give a Yes/No Prompt before deleting.
/A Select files to delete based on file_attributes
file_attributes:
R Read-only -R NOT Read-only
S System -S NOT System
H Hidden -H NOT Hidden
A Archive -A NOT Archive
Wildcards: These can be combined with part of a filename
* Match any characters
? Match any ONE character
Examples:
To delete HelloWorld.TXT
DEL HelloWorld.TXT
To delete "Hello Big World.TXT"
DEL "Hello Big World.TXT"
To delete all files that start with the letter A
DEL A*
To delete all files that end with the letter A
DEL *A.*
To delete all files with a .DOC extension
DEL *.DOC
To delete all read only files
DEL /a:R *
To delete all files including any that are read only
DEL /F *
Files are sometimes created with the reserved names: CON, AUX, COM1, COM2, COM3,
COM4, LPT1, LPT2, LPT3, PRN, NUL
To delete these use the syntax: DEL \\.\C:\somedir\LPT1
Folders
If a folder name is given instead of a file, all files in the folder will be
deleted, but the folder itself will not be removed.
Temporary Files
You should clear out TEMP files on a regular basis - this is best done at startup
when no applications are running. To delete all files in all subfolders of C:\temp\
but leave the folder structure intact:
DEL /F /S /Q %TEMP%
When clearing out the TEMP directory it is not generally worthwhile
removing the subfolders too - they don't use much space and constantly deleting
and recreating them can potentially increase fragmentation within the Master
File Table.
Deleting a file will not prevent third party utilities from un-deleting it again,
however you can turn any file into a zero-byte file to destroy the file allocation
chain like this:
TYPE nul > C:\examples\MyFile.txt
DEL C:\examples\MyFile.txt
ERASE is a synonym for DEL
If Command Extensions are enabled (default)
DEL /S [path]filename(s) will display a list of the files deleted
If Command Extensions are disabled:
DEL /S [path]filename(s) will display a list of any files it cannot find
DELTREE
Previous versions of Windows had the DELTREE command that deletes all files
and sub folders, DEL /s will delete all files, RD /s will remove all files and
folders including the root folder.
:: DELTREE.cmd
:: From tip 617 at Jsiinc.com
@echo off
pushd %1
del /q *.*
for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
popd
It devoured my paper, it was a really good paper - Ellen Feiss
Related Commands:
DELPROF Delete NT user profiles
Delrp - Delete a file/directory and NTFS reparse points.(Win
2K ResKit)
RD - Delete folders or entire folder trees ()
CleanMgr - Automated cleanup of Temp files, Internet
files, downloaded files, recycle bin
INUSE
- updated file replacement utility (may not preserve file permissions)
Delete in-use files with rm (Q120716)
Q320081
- Cannot Delete a File or Folder
Delete files older than X days
How to change the Windows NT recycle bin
Equivalent Linux BASH commands:
rm - Remove files
rmdir - Remove folder(s)