jazzIIIlove
asked on
file size via cmd/bat or vbs in terms of MBs
Hi;
I need a script bat/cmd/vbs that sorts the files of C drive in terms of MB on command prompt.
I don't need an installer solution like TreeSize.
Is there any in place?
Regards.
I need a script bat/cmd/vbs that sorts the files of C drive in terms of MB on command prompt.
I don't need an installer solution like TreeSize.
Is there any in place?
Regards.
There is a portable tree size util which can run without installing afaik. If you want batch or VBScript I have a few batches that may be of use here, e.g. second two show you the biggest 20 files in a directory and subdirs you choose, first one total size in subdir.
http://scripts.dragon-it.co.uk/links/batch-subdir-folder-size
http://scripts.dragon-it.co.uk/links/batch-biggest-files-in-folders
http://scripts.dragon-it.co.uk/links/vbscript-biggest-files-in-folders
You can sort files by size but only in one dir from a dir command. If you add /s it will sort them within each dir.
dir /o-s
If you really want to you can get a CSV file of any directory structure of all files with something like this which you could put in excel etc:
@echo off
pushd c:\startdir
for /f "tokens=*" %%F in ('dir /b /a-d /s') do echo "%%~dpF","%%~fxF",%%~zF > "%userprofile%\desktop\fil e-list.csv "
popd
start "" "%userprofile%\desktop\fil e-list.csv "
Powershell if OK gives other options
Steve
http://scripts.dragon-it.co.uk/links/batch-subdir-folder-size
http://scripts.dragon-it.co.uk/links/batch-biggest-files-in-folders
http://scripts.dragon-it.co.uk/links/vbscript-biggest-files-in-folders
You can sort files by size but only in one dir from a dir command. If you add /s it will sort them within each dir.
dir /o-s
If you really want to you can get a CSV file of any directory structure of all files with something like this which you could put in excel etc:
@echo off
pushd c:\startdir
for /f "tokens=*" %%F in ('dir /b /a-d /s') do echo "%%~dpF","%%~fxF",%%~zF > "%userprofile%\desktop\fil
popd
start "" "%userprofile%\desktop\fil
Powershell if OK gives other options
Steve
Example tree size portable --> http://portableapps.com/news/2012-10-20--treesize-free-portable-2.7-released
ASKER
A 3rd party program is out of question but i will give a try for the script. My aim is to see sorted files and folders w.r.t size
ASKER
Hi;
I used;
@echo off
pushd c:\startdir
for /f "tokens=*" %%F in ('dir /b /a-d /s') do echo "%%~dpF","%%~fxF",%%~zF > "%userprofile%\desktop\fil e-list.csv "
popd
start "" "%userprofile%\desktop\fil e-list.csv "
to use it I created a startdir directory as it was giving an error on line 2. I also created file-list.csv but now it gives file not found error on console. Am i missing something?
Regards.
I used;
@echo off
pushd c:\startdir
for /f "tokens=*" %%F in ('dir /b /a-d /s') do echo "%%~dpF","%%~fxF",%%~zF > "%userprofile%\desktop\fil
popd
start "" "%userprofile%\desktop\fil
to use it I created a startdir directory as it was giving an error on line 2. I also created file-list.csv but now it gives file not found error on console. Am i missing something?
Regards.
Sorry I should have said the "pushd" line was to take it to the directory under which you wanted the info. If you want the whole C: drive then it is going to make you a file with one line per file on the whole dir. If you wan that change the line to
pushd c:\
Steve
pushd c:\
Steve
ASKER
Hi Steve;
Seems fine except for the bytes. I want to have it MB and I added the /1048576 but it is treated as string. Any remedy?
Regards.
Seems fine except for the bytes. I want to have it MB and I added the /1048576 but it is treated as string. Any remedy?
Regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another way since we are talking Excel... if that is acceptable a few lines of VBA could scan down a directory structure and populate a spreadsheet for you. Say what you are after and will see what I can knock up.
Steve
Steve
if you do want to look at other ways just say... exceand macros in vba is great way of finding info and presenting it...
dir /a /s /os
/a --> Show all files
/s --> Show files in all subfolders
/os --> Order the files by size (can also use /o-s)
Is that what you are needing?
If you want, you can write that out to a file by changing it to
dir /a /s /os > c:\dirList.txt