title: Adapting forfiles command to look through folders instead of files
body: <p>I have written a backup command that deletes files within a <code>E:\Backup\ldap</code> directory that are older than two days. I have tested and this works fine.</p>
  
  <pre><code>(forfiles /p E:\Backup\ldap /s /d -2 /c "cmd /c echo @path &gt;&gt; E:\Backup\files_deleted_log_%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt &amp; cmd /c del /q @path")
  </code></pre>
  
  <p>I am in the process of adapting this command so that it looks at the top level folders within the specified directory and recursively deletes the folder and its contents if it is older than two days.</p>
  
  <pre><code>(forfiles /p E:\Backup\Sybase /d -2 /c "cmd /c if @isdir == true echo @path &gt;&gt; E:\Backup\files_deleted_log_%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt &amp; cmd /c if @isdir == true del /s /q @path")
  </code></pre>
  
  <p>I took out the first <code>/s</code> from the previous file command as I do not want to search recursively, I only want to look at the last modified dates of the top level folders within the <code>E:\Backup\Sybase</code> directory.</p>
  
  <p>I also added <code>if @isdir == true</code> to determine whether the file is a folder and updated the delete command to include <code>/s</code> so that a recursive delete is performed.</p>
  
  <p>Each time I execute the command though, nothing is deleted.</p>