Friday, August 27, 2010

Delete file from date

forfiles only work in windows 2000 /2003/ vista

Folder Location C:\Test\arch
file older than 5 days
*.* all file extension (*.txt, ......)

----------------

forfiles /p C:\Test\arch /s /m *.* /d -5 /c "cmd /c echo @path"


forfiles /p C:\Test\arch /s /m *.* /d -5 /c "cmd /c del @path"


FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D [+ | -] {MM/dd/yyyy | dd}]
----------

/p pathname Indicates the path to start searching. The default folder is the current working directory (.).

/m search mask Searches files according to a searchmask. The default searchmask is '*' .

/s Instructs forfiles to recurse into subdirectories. Like "DIR /S".

/C Indicates the command to execute for each file. Command strings should be wrapped in double quotes.

The default command is "cmd /c echo @file".


The following variables can be used in the command string:
@file - returns the name of the file. @fname - returns the file name without extension.
@ext - returns only the extension of the file.
@path - returns the full path of the file.
@relpath - returns the relative path of the file.
@isdir - returns "TRUE" if a file type is a directory, and "FALSE" for files.
@fsize - returns the size of the file in bytes.
@fdate - returns the last modified date of the file.
@ftime - returns the last modified time of the file.


/D date Selects files with a last modified date greater than or equal to (+), or less than or equal to (-), the specified date using the "MM/dd/yyyy" format; or selects files with a last modified date greater than or equal to (+) the current date plus "dd" days, or less than or equal to (-) the current date minus "dd" days. A valid "dd" number of days can be any number in the range of 0 - 32768. "+" is taken as default sign if not specified.



Examples: FORFILES /?
FORFILES
FORFILES /P C:\WINDOWS /S /M DNS*.*
FORFILES /S /M *.txt /C "cmd /c type @file | more"
FORFILES /P C:\ /S /M *.bat
FORFILES /D -30 /M *.exe /C "cmd /c echo @path 0x09 was changed 30 days ago"
FORFILES /D 01/01/2001 /C "cmd /c echo @fname is new since Jan 1st 2001"
FORFILES /D +8/19/2005 /C "cmd /c echo @fname is new today"
FORFILES /M *.exe /D +1
FORFILES /S /M *.doc /C "cmd /c echo @fsize"
FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"

No comments:

Post a Comment

Followers