Windows utility to delete files and folders recursively with support for deep file nesting and optional time offset filtering
This small Console utility deletes files and folders recursively and allows filtering files by date.
- Delete files with simple file specs like
c:\temp\*.*
or*.tmp
- Recursively delete files down the folder hierarchy (-r switch)
- Optionally delete empty folders (-f switch)
- Filter by files to delete based on days or seconds before current time (-d -s)
- Files can be optionally dumped into the Recycle Bin for recoverable deletes (-y)
- Preview mode lets you test run to see what would get deleted (-l)
- Works with deeply nested folder hierarchies (like NPM folders)
- Works around Windows MAX_PATH limitations
- Portable, single-file EXE file
To get the DeleteFiles executable you can use:
DeleteFiles is useful for common directory cleanup tasks, such as cleaning out temp folders, or log or backup files and so on. The timed features are especially useful for clearing out log and backup directories of dated files that are older than a specified number of days.
DeleteFiles is also useful for deleting deeply nested folder hierarchies that can't be deleted in Windows Explorer or other standard file utilities due to path lengths exceeding Windows default limitations (MAX_PATH). DeleteFiles can easily delete long paths as well as read-only, system and hidden files.
Because DeleteFiles is a small self-contained, single Exe it's easy to install and access it and use it for admin tasks in server batch/script files. Personally I use a number of DeleteFiles operations of scheduled tasks to manage database log cleanup (toss all logs older than 10 days), clean out all system temp folders, and scour the entire system for known temp files.
Command Line Options:
DeleteFiles <filespec> -r -f -y -l -d10 -s3600
Commands:
---------
HELP || /? This help display
Options:
--------
pathSpec FilePath and File Spec. Make sure to add a filespec
-r Delete files [R]ecursively
-f Remove empty [F]olders
-y Delete to Rec[Y]le Bin (can be slow!)
-l Disp[L]ays items that would be deleted
-q0..2 Quiet mode: -q0 - all (default) -q1 - No file detail
-q2 - No file detail, no summary
-dXX Number of [D]ays before the current date to delete
-sXX Number of [S]econds before the current time to delete
(seconds override days)
if neither -d or -s no date filter is applied (default)
Examples:
---------
DeleteFiles c:\temp\*.* -r -f - deletes all files in temp folder recursively
and deletes empty folders
DeleteFiles *.tmp -r - delete .tmp files recursively from current fodler down
DeleteFiles ""c:\My Files\*.*"" -r - deletes all files leaves folders
DeleteFiles c:\temp\*.* -r -f -d10 - delete files 10 days or older
DeleteFiles c:\temp\*.* -r -f -s3600 - delete files older than an hour
DeleteFiles c:\thumbs.db -r - delete thumbs.db on entire drive
- Uses ZetaLongPath by Zeta GMBH for long path deletion
Copyright © 2012-2015 Rick Strahl, West Wind Technologies
http://weblog.west-wind.com/
This utility is provided as is, free of charge under MIT licence, and is provided without warranty. You can use it as you see fit with no limitations and the source code provided can be modified as needed. If you make changes or fixes please put in a pull request or open an issue to get any changes added.
If you're feeling generous and you find this tool useful consider making a small donation:
This tool is published under MIT license terms:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
April 25th, 2015
- Fix Regression Bug with -d Switch Fixed issue where the -d switch was not properly filtering out files that were newer than the deletion date when running DeleteFiles with relative paths. Fixed up paths to properly use full file names rather than relative paths when checking for file status.
March 25th, 2015
-
Fix current Path Operation
Fixed issue when running without an absolute path out of the current folder so that wildcards*.tmp
and relative pathstemp\*.tmp
work out of the current folder. -
Updated Messages Cleanup the output display messages with cleaner numbers to summarize results.
February 28th, 2015
-
Support for paths longer than MAX_PATH
You can now delete deeply nested paths (such as nasty NPM hierarchies). Integrated with ZetaLongPaths to provide long path support on all directory and file delete operations. -
Delete ReadOnly, System and Hidden Files
Previously read-only files wouldn't delete. This updates now deletes any kind of file regardless of attribute settings. Locked and access denied files still will not work, but everything else will delete. -
Quiet Mode
Add -q0..2 switch to allow quiet operation that runs without showing every file and folder deleted. -q0 shows all - q1 only shows summary, -q2 shows only startup banner.