JSI Tip 8331. How can I find files that were created, or written, or accessed, in a given year?


In tip 8327, I counted files by year.

To find all the files on a drive, or in a folder, that were created, or written, or accessed, in a given year, I have scripted FileYearDetail.bat.

The syntax for using FileYearDetail.bat is:

FileYearDetail Folder Year \[DIR date switch, like /TC\]

Where Folder is the drive or folder you wish to enumerate, Year is the year, and \[DIR date switch, like /TC\] is:

/TC for Creation date.
/TA for Last Access date.
/TW for Last Written date.

NOTE: All sub-folders are enumerated.

NOTE: A File Not Found message indicates that a file/folder name contains command control characters.

FileYearDetail.bat contains:

@echo off
if \{%2\}

\{\} @echo Syntax: FileYearDetail Folder Year \[DIR date switch, like /TC\]&goto :EOF if not exist %1 @echo FileYearDetail - %1 NOT found.&goto :EOF setlocal ENABLEDELAYEDEXPANSION set folder=%1 set year=%2 set d1=dir %folder% /b /a /a-d /s set sw=/TW if not \{%3\}

\{\} set sw=%3 set f1=findstr /L /V "& !" set f2=findstr /L /C:"/%year%" for /f "Tokens=*" %%f in ('%d1%^|%f1%') do ( set file=%%f call :findit ) endlocal goto :EOF :findit for /f "Tokens=1" %%a in ('dir "%file%" /a %sw%^|%f2%') do ( @echo "%file%" )



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish