Last active
August 29, 2015 14:08
-
-
Save davidruhmann/dc3e7dd1f320e0c69287 to your computer and use it in GitHub Desktop.
SO26614571.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
call :DisplayRecursiveSubDirectoryInformation %1 | |
exit /b 0 | |
@echo off | |
setlocal disableDelayedExpansion | |
if "%~1"=="" (call :recurse ".") else call :recurse %1 | |
exit /b | |
:recurse | |
setlocal | |
set fileCnt=0 | |
for /d %%D in ("%~1\*") do call :recurse "%%~fD" | |
for /f %%F in ('dir /b /a-d "%~1\*" 2^>nul ^| find /v /c ""') do ( | |
set /a fileCnt+=%%F | |
) | |
echo %~f1 has %fileCnt% files %fileCntB% and the oldest file is from year I_NEED_YEAR_HERE | |
( | |
endlocal | |
set /a fileCnt+=%fileCnt% | |
) | |
exit /b | |
:DisplayRecursiveSubDirectoryInformation2 <Directory> [FileCountVar] | |
pushd "%~1" >nul 2>&1 || exit /b 1 | |
setlocal | |
set "FileCount=0" | |
for /f "delims=" %%A in ('dir /ad /b') do call :DisplayRecursiveSubDirectoryInformation "%%~fA" FileCount | |
call :DisplayDirectoryInformation "%~1" FileCount | |
endlocal & popd & 2>nul set /a "%~2+=%FileCount%" & exit /b %ErrorLevel% | |
:DisplayDirectoryInformation2 <Directory> [FileCountVar] | |
pushd "%~1" >nul 2>&1 || exit /b 1 | |
setlocal | |
set "FileCount=0" | |
set "FileYear=" | |
set "PathName=%~f1" | |
if not defined PathName set "PathName=%CD%" | |
rem for /f %%A in ('dir /a-d /b 2^>nul ^| find /v /c ""') do set "FileCount=%%~A" | |
rem for /f "tokens=3 delims=/" %%A in ('forfiles /C "cmd /c echo @fdate" 2^>nul') do for /f "d" | |
for /f "tokens=3 delims=/ " %%A in ('dir /a-d /o-d ^| find "/"') do set "FileYear=%%~A" & set /a "FileCount+=1" | |
echo %PathName% has %FileCount% files and the oldest file is from year %FileYear% | |
endlocal & popd & 2>nul set /a "%~2+=%FileCount%" & exit /b %ErrorLevel% | |
:DisplayRecursiveDirectoryInformation <Directory> | |
pushd "%~1" >nul 2>&1 && setlocal || exit /b 1 | |
set "FileYear=999999" & set "FileCount=0" | |
for /f "delims=" %%A in ('dir /ad /b') do call :DisplayRecursiveDirectoryInformation "%%~fA" | |
call :DisplayDirectoryInformation "%CD%" | |
endlocal & popd & set /a "FileCount+=%FileCount%" & set "FileYear=%FileYear%" & exit /b %ErrorLevel% {FileCount} {FileYear} | |
:DisplayDirectoryInformation <Directory> {FileCount} {FileYear} | |
pushd "%~1" >nul 2>&1 && setlocal || exit /b 1 | |
for /f "tokens=3 delims=/ " %%A in ('dir /a-d /o-d ^| find "/"') do set /a "FileCount+=1" & if "%%~A" lss "%FileYear%" set "FileYear=%%~A" | |
echo %CD% has %FileCount% files (total) and the oldest file is from year %FileYear% | |
endlocal & popd & set "FileCount=%FileCount%" & set "FileYear=%FileYear%" & exit /b %ErrorLevel% {FileCount} {FileYear} | |
:: Combine Child Folders' File Count with the Parents | |
:DisplayDirectoryInformation <Directory> {FileCount} | |
pushd "%~1" >nul 2>&1 || exit /b 1 | |
setlocal | |
set "FileYear=" | |
for /f "tokens=3 delims=/ " %%A in ('dir /a-d /o-d ^| find "/"') do set "FileYear=%%~A" & set /a "FileCount+=1" | |
echo %CD% has %FileCount% files and the oldest file is from year %FileYear% | |
endlocal & popd & set "FileCount=%FileCount%" & exit /b %ErrorLevel% | |
:: Isolate the Parents' File Count from their Childrens' | |
:DisplayDirectoryInformation <Directory> {FileCount} | |
pushd "%~1" >nul 2>&1 || exit /b 1 | |
setlocal | |
set "FileCount=0" | |
set "FileYear=" | |
for /f "tokens=3 delims=/ " %%A in ('dir /a-d /o-d ^| find "/"') do set "FileYear=%%~A" & set /a "FileCount+=1" | |
echo %CD% has %FileCount% files and the oldest file is from year %FileYear% | |
endlocal & popd & set /a "FileCount+=%FileCount%" & exit /b %ErrorLevel% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment