Skip navigation

JSI Tip 5730. Report large files by owner, using standard commands.


Using the size technique from tip 0494 and the ownership technique from tip 3109, I have scripted LargeFile.bat to report the ownership of files that exceed a specified size.

The syntax for using LargeFile.bat is:

LargeFile ReportFile SizeInBytes Path1 \[Path2 ... Pathn\]

where:

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

SizeInBytes is the file size that must be exceeded.

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

C:
"C:\Documents and Settings"
\\ServerName\c$\Users

Path2 - Pathn are optional additional search paths.

LargeFile.bat contains:

@echo off
setlocal
if \{%3\}

\{\} goto syntax set reportfile=%1 if exist %reportfile% del /q %reportfile% set size=%2 if "%size:~0,1%" EQU "0" goto syntax if "%size:~0,1%" GTR "9" goto syntax set /a size=%size% shift if exist %TEMP%\LargeFile.tmp del /q %TEMP%\LargeFile.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 /a fz=%~z1 if NOT %fz% GTR %size% goto :EOF set file=%1 set rawfile=%~nx1 set owner= for /f "Skip=4 Tokens=3*" %%b in ('dir /q /a-d %file%') do if not defined owner set owner=%%c if "%owner%"=="" goto :EOF call set owner="%%owner: %rawfile%=%%" set owner=%owner: =% set owner=%owner: "="% @echo %owner%,%file%,"%fz%">>%TEMP%\LargeFile.tmp goto :EOF :syntax @echo Syntax: LargeFile ReportFile SizeInBytes Path1 \[Path2 ... Pathn\] if exist %TEMP%\LargeFile.tmp del /q %TEMP%\LargeFile.tmp :finish if exist %TEMP%\LargeFile.tmp sort %TEMP%\LargeFile.tmp /O %reportfile% if exist %TEMP%\LargeFile.tmp del /q %TEMP%\LargeFile.tmp 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