JSI Tip 5731. Report old files by owner, using standard commands.

In tip 5690, I used Resource Kit tools to report old files by owner.

I have scripted OldFile.bat to report the ownership of files that are as old or older a specified date.

The syntax for using OldFile.bat is:

  OldFile ReportFile OldYYYYMMDD Path1 \[Path2 ... Pathn\]


  ReportFile is the path to a CSV file that will contain "Owner","Filename","DateModified".

OldYYYYMMDD is the newest date to report as old.

Path1 is the first path to start searching. The following are valid examples:

"C:\Documents and Settings"

Path2 - Pathn are optional additional search paths.

OldeFile.bat contains:

@echo off
if \{%3\}

\{\} goto syntax set reportfile=%1 if exist %reportfile% del /q %reportfile% set age=%2 shift if exist %TEMP%\OldFile.tmp del /q %TEMP%\OldFile.tmp :loop shift if \{%1\}

\{\} goto :finish set SPath=%1 if not exist %SPath% goto syntax FOR /R %SPath% %%a in (*.*) do call :parse "%%a">nul 2>&1 goto loop :parse set file=%1 set rawfile=%~nx1 set owner= for /f "Skip=4 Tokens=1-3*" %%b in ('dir /q /a-d %file%') do if not defined owner set dte=%%b&set owner=%%e if "%owner%"=="" goto :EOF for /f "tokens=1-3 delims=.:/-, " %%u in ('@echo %dte%') do ( for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do ( set %%x=%%u set %%y=%%v set %%z=%%w)) :: In the following set statement, use the names produced by echo.|date set dte=%yy%%mm%%dd% if "%dte%" GTR "%age%" goto :EOF call set owner="%%owner: %rawfile%=%%" set owner=%owner: =% set owner=%owner: "="% @echo %owner%,%file%,"%dte%">>%TEMP%\OldFile.tmp goto :EOF :syntax @echo Syntax: OldFile ReportFile OldYYYYMMDD Path1 \[Path2 ... Pathn\] if exist %TEMP%\OldFile.tmp del /q %TEMP%\OldFile.tmp :finish if exist %TEMP%\OldFile.tmp sort %TEMP%\OldFile.tmp /O %reportfile% if exist %TEMP%\OldFile.tmp del /q %TEMP%\OldFile.tmp endlocal

Hide 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.