title: Batch File: How to delete files sort by date if there are subfolders in the folder?
body: <p>Here is one example:</p>
  
  <p>There are 4 files:</p>
  
  <pre><code>C:\Test\1002.bak                  -- Created on Oct 2nd,2014
  C:\Test\1009.bak                  -- Created on Oct 9th,2014
  C:\Test\subfolder\1001.bak        -- Created on Oct 1st,2014
  C:\Test\subfolder\1008.bak        -- Created on Oct 8th,2014
  </code></pre>
  
  <p>I want to a batch file to delete older files sorted by date, all files including subfolders.</p>
  
  <p>It should be sorted like:</p>
  
  <pre><code>C:\Test\subfolder\1001.bak 
  C:\Test\1002.bak                  
  C:\Test\subfolder\1008.bak        
  C:\Test\1009.bak  
  </code></pre>
  
  <p>But if I run the below command, the result has been separated by subfolder.
  For instance, "dir /a-d /od /s > result.txt"</p>
  
  <p>result.txt:</p>
  
  <pre><code> Volume in drive C has no label.
   Volume Serial Number is AADB-DB05
  
   Directory of c:\test
  
  2014/10/02  11:40         4,220,416 1002.bak
  2014/10/09  07:02     1,453,321,216 1009.bak
  2014/10/09  18:44                 0 result.txt
                 3 File(s)  1,457,541,632 bytes
  
   Directory of c:\test\subfolder
  
  2014/10/01  10:51         4,220,416 1001.bak
  2014/10/08  07:02     1,418,283,008 1008.bak
                 2 File(s)  1,422,503,424 bytes
  
       Total Files Listed:
                 5 File(s)  2,880,045,056 bytes
                 0 Dir(s)  35,598,852,096 bytes free
  </code></pre>
  
  <p>"dir /a-d /od /s /b> result.txt"</p>
  
  <p>result.txt:</p>
  
  <pre><code>c:\test\1002.bak
  c:\test\1009.bak
  c:\test\result.txt
  c:\test\subfolder\1001.bak
  c:\test\subfolder\1008.bak
  </code></pre>
  
  <p>Is it possible to sort all files including all subfolders by date and then remove the older files when this folder disk size reach the limitation? thank you for your help.</p>