Link to home
Start Free TrialLog in
Avatar of nav2567
nav2567Flag for United States of America

asked on

use DIR to list folder content older than 10 years.

how do I use the DIR command to list content of a folder older than 10 years?  

Thanks.
Avatar of Mohammed Khawaja
Mohammed Khawaja
Flag of Canada image

ASKER CERTIFIED SOLUTION
Avatar of Mohammed Khawaja
Mohammed Khawaja
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

You can't do this with the basic built in DOS DIR command, there are no options to select by date.  You could do it with a batch file, here's an example of that.  Save as a BAT file and adjust the folder name.

(We could do this fairly easily in a VBS script too, let me know if you want to see that)

@echo off
setlocal EnableDelayedExpansion

REM Change to folder with files to check
pushd c:\temp

REM Calculate date 10 years ago in YYYYMMDD format
set CutoffDate=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%
set /a CutoffDate=%CutoffDate-100000

REM CHeck all files in the folder
for %%F in (*.*) do (

  REM Put file date in YYYYMMDD format
  set FileDate=%%~tF
  set FileDate=!FileDate:~6,4!!FileDate:~0,2!!FileDate:~-3,2!

  REM If file is older than 10 years then diplay it with it's date stamp
  if !FileDate! LSS %CutoffDate% (
    echo %%~tF  %%~F
  )
)

REM Return to original folder
popd

Open in new window

~bp