<div dir="ltr" style="text-align: left;">The following batch file uses &#8220;<i>Forfiles.exe</i>&#8221; for deleting files from the mentioned path. <i>Forfiles.exe</i> is supported only by Windows Vista, Windows 7, Windows Server 2003, and higher versions. Forfiles is present in the following path: <i>c:>;windows>;system32</i>. Before running the batch file, make sure that <i>forfiles.exe</i> is present in the path otherwise the batch file will not work</p>
<p>There are many other features for Forfiles but I have mentioned only few here.</p>
<p>Following command will delete IIS logs from exchange box , will run every Sunday, and will delete files in that folder older than 30 days. ; ; </p>
<p>Windows 2003<br />at 12:00 /EVERY:Su Forfiles.exe -p C:WINDOWSsystem32LogFilesW3SVC1 -m *.log -d -30 -c &#8220;Cmd.exe /C del @path&#8221; </p>
<p>Windows 2008<br />at 12:00 /EVERY:Su Forfiles.exe -p C:inetpublogsLogFilesW3SVC1 -m *.log -d -30 -c &#8220;Cmd.exe /C del @path&#8221;</p>
<p>To list all of the batch files on drive C, type:</p>
<pre>forfiles /p c: /s /m *.bat /c "cmd /c echo @file is a batch file"</pre>
<p> ; </p>
<pre>Syntax<br /> FORFILES [/p <i>Path</i>] [/<b>m</b><i> SrchMask</i>] [/s] [/<b>c</b><i> Command</i>] [/<b>d</b><i> </i>[+ | -] {<i>date</i> | <i>dd</i>}] <br />Key<br /> /p <i>Path</i> The Path to search (default=current folder)<br /> /m <i>SrchMask</i> Select files matching the specified search mask<br /> default = *.*<br /> /s Recurse into sub-folders<br /> /C <i>command</i> The command to execute for each file.<br /> Wrap the command string in double quotes.<br /> Default = "cmd /c echo @file"<br /> The Command variables listed below can also be used in the<br /> command string.<br /> /D <i>date</i> Select files with a last modified date greater than or <br /> equal to (+), or less than or equal to (-),<br /> the specified <i>date</i>, using the region specific date format<br /> typically "MM/DD/yyyy" or "DD/MM/yyyy"<br /> /D + <i>dd</i> Select files with a last modified date greater than or<br /> equal to the current date plus "dd" days. (in the future)<br /> /D - <i>dd</i> Select files with a last modified date less than or<br /> equal to the current date minus "dd" days. (in the past)<br /><br /> A valid "dd" number of days can be any number in<br /> the range of 0 to 32768. (89 years)<br /> "+" is taken as default sign if not specified.</pre>
</div>

