Monday, August 25, 2014

Batch file deletion in Windows using Forfiles command

Sometimes you may face situation when you have lot of files (several thousands) in some folder. It could happen because some program is creating them, logging something etc. When the files are really many than Windows explorer could hang-up and become really slow and even unresponsive. One of easy solutions is use special command through command prompt.
Must admit that this tool is available only in some newer Windows OS versions starting from Vista. To use it open command prompt and look for a Windows built-in command forfiles. This command selects batch of files based on specific criterion. After selection you can use this set in scripts and run commands affecting all set. For example if we want to delete all files in folder that are modified in one specific date in our case it would be drive C folder Data modification date 25 of August 2014. To perform this operation run command in command prompt window:
C:\Data\forfiles /D 08/25/2014 /C "cmd /c del @file"
 More info about forfiles command you can get here and here.

No comments:

Post a Comment