bat script regularly delete backup files

Delete the D: File \ rar types under yswbak directory 6 days ago
@echo off 
forfiles /p D:\yswbak /m *.rar /d -6 /c "cmd /c del @path"
1, in a batch file, if the first command with @ to indicate that this command does not print out, print out only the result that is significantly @ back to close the command itself
2, a line indicates a comment in :: batch 
3, ECHO ON means that the following command (this command is not included), before executing the command will first print command 
   ECHO OFF command represented by the following (excluding the present command), only the results of printing, the print command is not itself 
  @ECHO OFF means that the following command (including this command), only the results of printing, the print command itself is not 
4, the command echo XXX, XXX is the result, is the echo XXX command itself

FORFILES

FORFILES [/ P the Path] [/ m SearchMask] [/ S] [/ C the Command] [/ D [{+ | -}] [{the MM / DD / YYYY | DD}]]
FORFILES windows is a software platform tools, select a file and run the command to manipulate files.

Selection criteria include file name and last modified date.

It can be used directly from the command line, it can also be used in batch files or other scripts.

The forfiles command initially provided in the Windows NT Resource Kit as an add-on. It became a standard utility for Windows Vista as part of the new management functionality.

usage

forfiles command has several command line options. If no options or arguments, it prints the current directory name of each file.

 

Description:

/ p specified path
/ s including subdirectories, by default, only a single designated directory search.
filename mask / m lookup
/ d specified date, absolute and relative date date herein refers -7 7 days before the date of the current   
command line / c run command indicates for each file. Command string should be in double quotes.

Default command is "cmd / c echo @file".

The following variables can be used in the command string:

Copy the code
    @file - returns the file name. 
    @fname - return without the extension of the file name. 
    @ext - returns only the extension of the file. 
    @path - returns the full path of the file. 
    @relpath - returns the relative path to the file. 
    @isdir - If the file type is a directory, return "TRUE"; if the file returns "FALSE". 
    @fsize - to return the file size in bytes. 
    @fdate - Returns the last modified date on the file. 
    @ftime - return to the file was last modified time
Copy the code

Date grammar

date parameters may be given as a character date, format [/ d [{+ | -}] [{MM / DD / YYYY | DD}]]

Where MM / DD / YYYY is the specified date, DD is the current date minus DD days
if the date parameter with a minus (-) at the beginning, only a select previously modified before a given date or modified files (older files / too).
Otherwise, select only the files (newer files / modify later) to modify or after a given date. It can be given explicit plus sign (+), but this is the default.
Note that both modes at a given date to select the file. Not only select the file at a given date (not before or after).

 

Example:

Delete the D: \ directory under db_bak (including subdirectories) 20 days before the rar file, type:
FORFILES / the p-"D: \ db_bak" / S / m * .rar / d -20 / c "cmd / c del @ path "

To list the C: all files on before January 1, 1993 to create and display "file is quite old!", Type:
FORFILES / PC:. / / S / m * * / d t-01,011,993 / c "cmd / c echo @file is quite old!"

List Drive C: all the batch file, type:
FORFILES / PC: / / S / m * .bat / C "cmd / C echo @file IS A BATCH File"

Lists drive C: on all directories, type:
FORFILES / PC: \ / S /m*.* / c "cmd / c == IF @ isdir to true echo @file IS A Directory"

Guess you like

Origin www.cnblogs.com/superduan/p/11810661.html