Introduction
Forfiles is a batch delete command that comes with Windows, it is a good choice to judge the history file by using it to judge the time by the modification Date property of the file itself.
Grammar
forfiles [/P Path] [/M searchmask] [/s] [/C Command] [/d [{+ |-}] [{mm/dd/yyyy | DD}]]
[/P Path]: Specifies the path, of course, the directory can be used "." [/M Searchmask]: Search By default is *. * [/s]: Traverse subdirectories for search, including current directory [/d [{+ |-}] [{mm/dd/yyyy | DD}]]: Select a file with a date greater than or equal to (+) (or less than or equal to (-)) specified date, default +where mm/DD/YYYY is the specified date, DD is the current date minus DD days, and the default is DD. The effective range of DD is 0-32768For example:/D- the: Find files up to 15 days ago/d ./ A/9: Specifies that the found file date is 2016/ A/9[/C Command]: Specifies the command to execute in the format [/C"cmd/c rd/s/q @path"]; double quotes inside the/c followed by the command to be executed. Variable: @file display file name @fname displays a file name with no extension @ext displays the full path to the file extension @path the relative path of the @relpath file @isdir if the file type is a directory, evaluates to True, otherwise the value is False@fsize Displays the file size in bytes @fdate display the last modified date stamp in the file @ftime display the last modified timestamp in the file
Example
1. Lookfor files or folders with the name "--" in the "D:\ Backup \ Data" directoryand the modification time greater than 15 days
forfiles.exe/p d:\backup\data/m *-*-*/d-"cmd/c echo @path"
2. Delete,/s/q (the file is also deleted under the/S folder,/q Force Delete is not prompted)
forfiles.exe/p d:\backup\data/m *-*-*/d-"cmd/c rd/s/q @path"
Note: path does not support "\\url\" This shared path, RD (delete folder), Del (delete file)
Summary
Note: pursuer.chen Blog:http://www.cnblogs.com/chenmh This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly give the link. Welcome to the exchange of discussions |
Windows forfiles (Delete history files)