@echo off setlocal EnableDelayedExpansion color 1f cls title Subfolder MP4 Counter :: ================================================= :: --------------- Control Panel ------------------ :: ================================================= :: Set the file extension you want to count here set "File_Extension_To_Count=*.mp4" :: Set the alignment padding for the output set "Folder_Name_Width=40" set "File_Count_Width=8" :: Long string of spaces we can slice from set "Spaces= " echo Starting file count for %File_Extension_To_Count%... echo. call :Process_Subfolders echo. echo Script finished. echo . . . pause >nul goto :EOF :: ---------------------- Process_Subfolders ------------------------------ :Process_Subfolders echo Searching for subfolders and counting files... echo -------------------------------------------------- :: dir /b /ad = just folder names :: findstr /r /v "^_" = drop any that start with underscore for /f "delims=" %%A in ('dir /b /ad ^| findstr /r /v "^_"') do ( call :Count_Files "%%A" ) echo -------------------------------------------------- echo Folder processing complete. goto :EOF :: ---------------------- Count_Files ------------------------------ :Count_Files :: %1 = subfolder name set "ThisFolder=%~1" set "File_Count=0" :: Count *.mp4 (or whatever extension) in that folder for /f "delims=" %%C in (' dir /b /a-d "%~1\%File_Extension_To_Count%" 2^>nul ^| find /c /v "" ') do ( set "File_Count=%%C" ) :: Build right-padded folder name (cut to Folder_Name_Width) call :PadAndTrimRight "!ThisFolder!" "!Folder_Name_Width!" Aligned_Name :: Build left-padded count (cut to File_Count_Width) call :PadAndTrimLeft "!File_Count!" "!File_Count_Width!" Aligned_Count echo !Aligned_Name! : !Aligned_Count! goto :EOF :: ---------------------- PadAndTrimRight ------------------------------ :: Args: :: %1 = text to pad on RIGHT :: %2 = total width :: %3 = output var name :: :: Example: "Movies" (6 chars), width 10 -> "Movies " :PadAndTrimRight set "PTR_Text=%~1" set "PTR_Width=%~2" :: Append spaces to the right set "PTR_Temp=!PTR_Text!!Spaces!" :: Now trim to desired length set "PTR_Temp=!PTR_Temp:~0,%PTR_Width%!" :: Store into caller's variable name set "%~3=!PTR_Temp!" goto :EOF :: ---------------------- PadAndTrimLeft ------------------------------ :: Args: :: %1 = text to pad on LEFT :: %2 = total width :: %3 = output var name :: :: Example: "12" width 6 -> " 12" :PadAndTrimLeft set "PTL_Text=%~1" set "PTL_Width=%~2" :: Put spaces in front, then the text set "PTL_Temp=!Spaces!!PTL_Text!" :: Keep only the RIGHT-most N characters :: Trick: get length N from PTL_Width for /f "tokens=1,2 delims=:" %%X in ("!PTL_Width!:dummy") do ( set "PTL_Temp2=!PTL_Temp:~-%PTL_Width%!" ) set "%~3=!PTL_Temp2!" goto :EOF