Page 1 of 1
Display File Sizes
Posted: 17 Aug 2010 17:16
by tkinsella
Hello!
I am trying to create batch file that will list the size of every file in a directory and it's sub-directories. This will then export the data into a txt file. Any thoughts?
Thanks!
Re: Display File Sizes
Posted: 18 Aug 2010 08:09
by aGerman
Try this
Code: Select all
>your.txt type nul
for /r "D:\your\folder" %%a in (*) do >>your.txt echo %%~za %%a
Regards
aGerman
Re: Display File Sizes
Posted: 18 Aug 2010 09:15
by tkinsella
Thanks! How would I be able to sort this list by size, largest to smallest?
Thank you!
Re: Display File Sizes
Posted: 18 Aug 2010 10:39
by aGerman
It's not a simple thing.
First I thought about processing the DIR command, but the switch /o-s will sort the output for each subfolder separately.
Then I thought I could use a "bubble sort", but this does not work if the size is larger than 2^31 -1 bytes.
Finaly should be doable to use the SORT command. Because it sorts alphanumerically, we have to prepend some zeros and cut it to a string with fix length.
Code: Select all
@echo off &setlocal
(
@echo off
for /r "D:\your\folder" %%a in (*) do (
set "size=000000000000000000000000%%~za"
call echo %%size:~-25%% %%a
)
)|sort /r /o "your.txt"
Regards
aGerman
Re: Display File Sizes
Posted: 18 Aug 2010 22:43
by ghostmachine4
download
coreutils for windows, after that , use du together with sort to do the job.
that's it.