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!
Display File Sizes
Moderator: DosItHelp
Re: Display File Sizes
Try this
Regards
aGerman
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
Thanks! How would I be able to sort this list by size, largest to smallest?
Thank you!
Thank you!
Re: Display File Sizes
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.
Regards
aGerman
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
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Display File Sizes
download coreutils for windows, after that , use du together with sort to do the job.
that's it.
Code: Select all
du -sk * |sort -rn
that's it.