nav2567
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.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
(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
~bp
http://social.technet.microsoft.com/Forums/windowsserver/en-US/ae123e5c-801e-4c95-a89c-1aa8c554f2af/list-files-older-than-x-days-dump-to-excelcsv