JSI Tip 9250. How can I determine the files that have not been accessed, or modified, in the past N days?


I have scripted AnalDT.bat to determine the files that have not been accessed, or modified, in the past N days.

The syntax for using AnalDT.bat is:

AnalDT A|C days Path

Where:

A|C       A indicates check for accessed, C indicates check for changed/created (Written).

Days      Is the number of days in the past to check, from 0-9999.

Path      is the Drive Letter or Folder to check.
The output is displayed on the console, in the following CSV format:

"Fully Qualified File Name","YYYYMMDD","A|W"

You can redirect the output to a file using:

AnalDT A|C days Path>filename.

NOTE: AnalDT.bat uses DatePorM.bat, which must be in a folder that is in your PATH.

AnalDT.bat contains:

@echo off
setlocal ENABLEDELAYEDEXPANSION
if \{%3\}==\{\} goto err
set AC=%1
set /a days=10000%2%%10000
if %days% LSS 0 goto DTN
set /a days=0 - %days%
:DTN
set where=%3
if /i "%AC%" EQU "A" set AC=A&goto OK
if /i "%AC%" NEQ "C" goto err
set AC=W
:OK
if not exist %where% goto errnf
call DatePorM %days% DT
set DTC=%DT:~6,4%%DT:~0,2%%DT:~3,2%
for /f "Tokens=*" %%a in ('dir /b /s /a /a-d %where%') do (
 for /f "Tokens=1,2,3 Delims=/ " %%f in ('dir /a /T%AC% /4 "%%a"^|FIND "/"') do (
  set MM=%%f
  set DD=%%g
  set YY=%%h  
  set YY=!YY: =!
  set /a MM=100!MM!%%100
  set /a DD=100!DD!%%100
  if !MM! LSS 10 set MM=0!MM!
  if !DD! LSS 10 set DD=0!DD!
  set DTF=!YY!!MM!!DD!
  if "!DTF!" LEQ "%DTC%" @echo "%%a","!DTF!","%AC%"
 )
)
endlocal
goto :EOF
:err
@echo Syntax: AnalDt A^|C days Path
endlocal
goto :EOF
:errnf
@echo AnalDT %AC% %2 %where% - NOT FOUND.
endlocal



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