Thursday, February 4, 2010

Display & Delete Files with Batch Command

Looking forward this useful script, you can display files detail with specific date criteria.

You can this script on Windows Server 2003


Just create bat file –>  DisplayFile.bat
and the content of that file :

for help you can type this script on cmd prompt: forfiles /?

Format scripts







FORFILES [/p Path] [/s] [/d Date] [/m Mask] [/c Command]


Path   : Path to search  (default=current folder)

-s : Recurse into sub-folders

Date : This can be
+DDMMYY to select files newer than a given date
(filedate >=DDMMYY) or
-DDMMYY to select files older than a given date
(filedate <=DDMMYY) or
(Recent versions format the date mask as: +MM/DD/YY

+DD to select files newer than DD days ago or
-DD to select files older than DD days ago

Mask : Search mask (wildcards allowed) default=*.*
Command : Command to execute on each file. default="CMD /C Echo @FILE"



File Bat Contents


FORFILES /p D:\Folder2\ /m *.*  /d -2 /c "cmd /c echo @FILE  ###################  @FDATE"


pause



image 



if you want to delete file with date criteria, you can use this script




Delete file with batch command






FORFILES /p D:\Folder2\ /m *.*  /s /d -2 /c "cmd /c echo del "@path" & del "@FILE"""

pause



Reference : http://ss64.com/nt/forfiles.html






No comments: