http://www.csnserver.com
Click here for Low cost website hosting!

IP Address Lookup
IP Address

Microsoft Windows Tips And Tricks!



Welcome!

align='center'>Find Files And Act On Them From The Command Line In All Current Versions Of Windows Since XP



The Ďfindí Command is a very powerful Linux/Unix command which provides various options for searching files based on different criteria. One of these options allows users to search for files based on the modification/access/creation time of the file. In Windows, we donít have such a powerful command. But we do have a command to search for files based on the file modification time. It canít be used to find files based on file creation/access time. Still this command is much better than nothing at all. Below you can find how to use the 'forefiles' command.

Find files modified in the last 2 months:
forfiles /P directory /S /D +60

Files Listed With Forfiles At Cmd Prompt

This command searches for files created in the folder (specified with /P) in the last 60 days. Specifying /S makes it search for such files recursively in all subfolders.
Get the list of files in the current folder which are modified in last 5 days.
forfiles /S /D +5

Files Listed With Forfiles At CMD Prompt Current Dir

Note that we have not used /P as we want to search in the current working directory only.
Get the list of files which are not modified in the last 5 days.
forfiles /S /D -5

Fiels Listed With Forfiles At CMD Prompt Not Moded In Last 5 Days

If there are no files meeting the condition, the command prints the following message.
H:\>forfiles /S /D +8
ERROR: No files found with the specified search criteria.

File With Forfiles At CMD Prompt Files Nto Found MSG

Find files based on modification date:
To find files modified after September 1st 2013, we can run the below command.
forfiles /P directory /S /D +09/01/2013

File With Forfiles At CMD Prompt Files After Mod Date

To find files modified before July 21st 2013:
forfiles /P directory /S /D -07/21/2013

Files With Forfiles At CMD Prompt Files Before Mod Date

Execute commands on the files selected:
forfiles has an equivalent functionality similar to -exec option with linux/unix find command. This can be used to run commands on the files set returned by the command.
The syntax of the command is:
forfiles /D date /C "cmd /c command @file"
Move files to another folder based on modification time.
Letís say we want to move the files which are not modified in the last 5 days to another folder (G:\archiveFolder). The command for this would be as below.
forfiles /S /D -5 /C "cmd /c move @file G:\archiveFolder"

Files With Forfiles At CMD Prompt Files Moved By Date

This command looks and processes files in subfolders also, Ď/Sí can be removed to perform this only for the files in the current folder.
Delete files in the current folder which are modified in the last 7 days.
forfiles /D +7 /C "cmd /c del @file"

Files With Forfiles At CMD Prompt Files Deleted by Date

Be cautious while running these commands, verify that you are deleting the right set of files, otherwise the data lost may not be recoverable. Use these commands at your own risk.
To remove files from subfolders also:
forfiles /S /D +7 /C "cmd /c del @file"

Files With Forfiles At CMD Prompt Files Deleted By Date 2

Thanks for visiting mswintips.com.

Return to Index Page


Valid HTML 4.01 Transitional
Copyright ©2018 CSN All Rights Reserved