JSI Tip 8506. How can I detect if a folder contains an 'Excessively Large Number Of Files'?

A poster in the 'microsoft.public.windows.file_system' newsgroup asked if there was a way to detect if a folder contained an 'Excessively Large Number Of Files'.

I have scripted ExcessivelyLargeNumberOfFiles.bat to detect if a specified folder, and/or its' sub-folders, contained more than N files.

The syntax for using ExcessivelyLargeNumberOfFiles.bat is:

ExcessivelyLargeNumberOfFiles Folder1 Tolerance1 \[Folder2 Tolerance2 ... FolderN ToleranceN\]

where each FolderX and ToleranceX pair specifies a folder path to be checked for more than the specified number of files.

ExcessivelyLargeNumberOfFiles.bat contains:

@echo off
if \{%2\}

\{\} @echo Syntax: ExcessivelyLargeNumberOfFiles.bat Folder1 Tolerance1 \[Folder2 Tolerance2 ... FolderN ToleranceN\]&goto :EOF setlocal :loop if \{%1\}

\{\} goto finish set folder=%1 set work=%2 set /a tol=0 :tolloop if "%work%" EQU "" goto shiftit if "%work:~0,1%" NEQ "0" goto settol set work=%work:~1% goto tolloop :settol set /a tol=%work% :shiftit shift shift if not exist %folder% @echo Folder %folder% does NOT exist.&goto :loop set subf=%folder% call :testsub for /f "Tokens=*" %%a in ('dir %folder% /b /ad /s') do ( set subf="%%a" call :testsub ) goto loop :finish endlocal goto :EOF :testsub set /a num=0 for /f "Tokens=1-4" %%a in ('dir %subf% ^|Find " File"^|Find " bytes"') do ( if "%%a" NEQ "0" set /a num=%%a ) if %num% LEQ %tol% goto loop @echo %subf% %num%

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.