Link to home
Start Free TrialLog in
Avatar of otyew
otyewFlag for Malaysia

asked on

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.....
Avatar of Venugopal N
Venugopal N
Flag of India image

Use the DIRUSE.exe...

For more details refer the below link..
http://technet.microsoft.com/en-us/library/cc781726(WS.10).aspx
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"
Avatar of otyew

ASKER

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

Steve
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"?
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.
Avatar of otyew

ASKER

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?
Avatar of shankarmani
shankarmani

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

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
Avatar of otyew

ASKER

use a lot of system resources till it hangs my file server, good for small folders.
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...
You will notice also when you right click a folder and do properties that takes ages too.... and longer from over the wire.