use DIR to list folder content older than 10 years.

Posted on 2013-09-19
Medium Priority
Last Modified: 2013-10-01
how do I use the DIR command to list content of a folder older than 10 years?  

Question by:nav2567
  • 2
LVL 25

Expert Comment

by:Mohammed Khawaja
ID: 39507560
LVL 25

Accepted Solution

Mohammed Khawaja earned 1500 total points
ID: 39507603
Also look at command forfiles.exe included with windows.  I don't have my PC and can't give you the syntax.
LVL 60

Expert Comment

by:Bill Prew
ID: 39507728
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

Open in new window


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question