I'm looking for a way to print (or write to file) the folder tree of my windows PC, including the size of each folder - but not of single files. The output should look like: - My Documents/pictures/selfies/ - 100MB - My Documents/movies/ - 1000MB - My Music/Mozart/ - 300MB ..and so forth
notes: 1) single files can be listed if there's no way around it, but in a way that I can programmatically (i.e. with parsing or regex) remove them from the list later..
2) the aim is to create a hierarchical file like http://bl.ocks.org/mbostock/raw/1283663/readme.json so a .json would be best, but not a requirement: I'll parse the text and create a .json file as a second step.
3) this is what I have, but I have no idea on how to convert it to my needs.
@echo off
setlocal disabledelayedexpansion
set "folder=%~1"
if not defined folder set "folder=%cd%"
for /d %%a in ("%folder%\*") do (
set "size=0"
for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:" "') do if "%%~c"=="" set "size=%%~b"
setlocal enabledelayedexpansion
echo(%%~nxa # !size!
endlocal
)
endlocal
4) I can only work in python and batch scripting on my machine :(
Thanks all AC
Here's the Python (2.7 compatible syntax) script:
For a directory tree like (numbers next to files, are their sizes):
the outputs would be:
files = False
:files = True
:Those are python dictionaries (I formatted them for readability) which are perfectly compatible with json (you can try:
json.dumps(d)
(whered
is a dictionary)).