List the folder name and its size

Hi, I'm doing a housekeeping and to keep track of the users folder usage. Would like to know the CMD or VBS script to export the folder name and the size. I have tried to search others codes but it does not seems to work.

i need to list the folder size of all the folders are in the E:\homedirectory folder. eg:

E:\homedirectory\my folder   --> 200MB

something like that.....
otyewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Venugopal NCommented:
Use the DIRUSE.exe...

For more details refer the below link..
http://technet.microsoft.com/en-us/library/cc781726(WS.10).aspx
0
Steve KnightIT ConsultancyCommented:
Or Treesize - http://www.jam-software.com/freeware/index.shtml

If you did want a batch file we can do it based on data from a dir /s command, e.g. this is what my script here does for you:

http://scripts.dragon-it.co.uk/links/batch-subdir-folder-size

@echo off
if not "X%~1"=="X" cd /d "%~1"
:skipset
setlocal enabledelayedexpansion
set log=log.txt

echo Results for subdirs of %cd%
echo.
echo Results for subdirs of %cd% >%log%
for /f "tokens=*" %%a in ('dir /ad /b') do (
echo Checking %%a
for /f "tokens=3" %%B in ('dir /s /-c %%a ^| find "File(s)"') do set filesize=%%B
set Mb=!filesize:~0,-6!
if X!Mb!==X set Mb=0
echo ... !Mb! Mb
(echo %%a,!Mb! Mb)>>%log%
)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve KnightIT ConsultancyCommented:
BTW you add this script as shortct on your desktop and drag E:\homedirectory\ onto it from explorer or add E:\homedirectory\ to the working directory or on the command line of the shortcut, or run it from cmd.exe prompt as:

dirsize.cmd "E:\homedirectory"
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

otyewAuthor Commented:
it seems not to be working. is it because of the access right issue? do i need to have full access to it?
0
Steve KnightIT ConsultancyCommented:
You would need to be able to see all the files and subdirs of course yes, for ANY method.

Steve
0
Steve KnightIT ConsultancyCommented:
read access would do.  What happens when you do:

cd /d "E:\homedirectory"
dir userX /s

Does it give you a total at the end, listing files as it goes or "access denied"?
0
Steve KnightIT ConsultancyCommented:
And what isn't working btw, could you be more specific please?  Does it have any ouput, assuming you are talking of my batch script? By default the script creates a log file in the same dir you run it from.... you can change that in the line set log=log.txt, e.g. to set log="%userprofile%\desktop\log.txt" or another path you have rights to.
0
otyewAuthor Commented:
hi dragon-it,

when u said that "BTW you add this script as shortct on your desktop and drag E:\homedirectory\ onto it from explorer"

i tried to drag the folder there but where will the output file goes to?
0
shankarmaniCommented:
hi

follow below script it wil heip u to find the size of the folder . result will be there in c:\results.txt

 on error resume next
Set FSO = CreateObject("Scripting.FileSystemObject")
    Set Drv = FSO.Drives("C:")
    Set Root = Drv.RootFolder
Set objFile = FSO.CreateTextFile("C:\results.txt", 2, True)
 For Each SubFld In Root.SubFolders
ShowSubFolders FSO.GetFolder(SubFld)
Next
objFile.Close


Sub ShowSubFolders(Folder)
    For Each Subfolder In Folder.SubFolders
        'Wscript.Echo Subfolder.Path
        Set objFolder = FSO.GetFolder(Subfolder.Path)
objFile.WriteLine  Folder & "\" & objFolder.Name & "-" & objFolder.Size /
1024
        ShowSubFolders Subfolder
    Next
End Sub

0
Steve KnightIT ConsultancyCommented:
OK.  The script will write to log.txt in the root of the area at the moment, i.e. E:\homedirectory\log.txt  You can change that to point anywhere else you want to as shown above.  If you add the line

notepad %log% to the end of the script then it will open it when it has finished too.  It also shows to the screen it's progress.  Are you getting any output now?

@echo off
if not "X%~1"=="X" cd /d "%~1"
:skipset
setlocal enabledelayedexpansion
set log="log.txt"

echo Results for subdirs of %cd%
echo.
echo Results for subdirs of %cd% >%log%
for /f "tokens=*" %%a in ('dir /ad /b') do (
echo Checking %%a
for /f "tokens=3" %%B in ('dir /s /-c %%a ^| find "File(s)"') do set filesize=%%B
set Mb=!filesize:~0,-6!
if X!Mb!==X set Mb=0
echo ... !Mb! Mb
(echo %%a,!Mb! Mb)>>%log%
)
notepad %log%

Save that as dirsize.cmd in  E:\homedirectory and it wll run from that dir if you just double click it in explorer or run it from cmd.exe in that dir.  If you want it to run from other dirs then move it there or if you create a shortcut to the batch file, e.g. on your desktop and then drag a foldername to it from explorer then it will run it from that dir for you.

Steve
0
otyewAuthor Commented:
use a lot of system resources till it hangs my file server, good for small folders.
0
Steve KnightIT ConsultancyCommented:
Sorry i it slows you server... aill it is doing is a dir /s on each subdir ... but that does take some while, best ran from a server directly of course rather than over the wire...
0
Steve KnightIT ConsultancyCommented:
You will notice also when you right click a folder and do properties that takes ages too.... and longer from over the wire.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.