
csv file in the run directory, folderSizes.csv. I took Williamsons code and made it export each line to a. > %temp%\tmp.vbs echo wsh.echo FormatNumber(eval(%~1%val%),1) Just in case you'd rather have it in those formats. Using MC ND's excellent code, I've added conversion to Kb, Mb, Gb, etc. If a file needs to be created, redirect the output of the batch to a file getSizes.cmd "c:\temp" > C:\folderList.txt Then the name (and extension if it has) of the folder and the size of the elements under it is echoed to console. It iterates over the indicated folder (passed as parameter to the batch file, or current directory if there is no paramter).įor each folder inside it ( for /d) a recursive dir command is executed inside the inner for command, and from its output, the summary line at the end (extracted by findstr) is parsed (the tokens in for command) and the total size of all the files under this subfolder is retrieved.

For each folder in the list, use dir command to retrieve the size of the files under the folder offįor /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:" "') do if "%%~c"="" set "size=%%~b"
