JSI Tip 9370. How can I display the file name and size of the largest file in a drive or folder?


I have scripted MaxSize.bat to display the fully qualified file name and file size of the largest file in a drive or folder.

The syntax for using MaxSize.bat is:

MaxSize DriveOrFolder \[non-blank for sub-folders\]

Where DriveOrFolder is the drive letter of folder path to search, like C: or C:\folder or "C:\Documents and Settings\Jerry\My Documents", and any non-blank second parameter will cause all sub-folders to be searched.

MaxSize.bat contains:

@echo off
if \{%1\}

\{\} @echo Syntax: MaxSize Drive: \[non-blank for sub-folders\]&goto :EOF setlocal ENABLEDELAYEDEXPANSION set /a size=0 set file="NONE" if not \{%2\}

\{\} set sub= /s pushd %1 set folder=%1 set folder=%folder:"=% for /f "Tokens=*" %%a in ('dir %1 /b%sub%') do ( if %%~za GTR !size! set size=%%~za&set file=%%a ) set work=%file:\=% if "%work%" EQU "%File%" set file=%folder%\%file% @echo "%file%" %size% popd 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