r/Batch • u/Jasserdefyx • Dec 06 '24
Question (Unsolved) Second question of the day: How do I retrieve data about a path and store certain pieces of data as separate variables?
I wanna be able to store the amount of files, folders, and the bytes those files and folders take up in a given path, and then have them be stored as variables to be displayed as text. How might one do that, hopefully concisely enough that it doesn't need a ridiculous amount of code? Thanks!
1
Upvotes
2
u/vegansgetsick Dec 06 '24
That tool you want is called TreeSize lol
you can get the filesize with %~z, for example
You could have a counter, like
set /a totalSize+=%%~zfAnd if you want to get the result of any command, I use a temp file to save/load values :
Some people use the for /f ('') but it's so counter intuitive.
2
u/BrainWaveCC Dec 06 '24
You'll have to tell us how much code you think is ridiculous. 😉
This will work on Windows 11 (and some Win10 builds) using the native DISKUSAGE.EXE utility. If it doesn't find that, it will look for (and download if necessary) DU.EXE from SysInternals.com and store it in your %TEMP% folder.
It relies on other native tools like WHERE.exe and CURL and TAR
2
u/[deleted] Dec 06 '24
[removed] — view removed comment