JSI Tip 9645. How can I return the disk space used by an owner in a folder?

Jerold Schulman

August 17, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted OwnerSize.bat to return the disk space megabytes used by an owner in a folder.

NOTE: OwnerSize.bat uses .

The syntax for using OwnerSize.bat is:

OwnerSize Folder Owner Size [/s]

Where:

Folder  is the folder path to enumerate, like C:Users or "C:Documents and SettingsJerry", or D:.Owner   is the owner, like BUILTINAdministrators or JSIINCJerry or JSI009Jerry.        If only Jerry is used, all matching accounts are summed.        if deleted is used, the space used by all deleted user's files is summed.Size    is a <a href="https://www.itprotoday.com/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed numeric environment variable</a> that will contain the size in megabytes./S      is an optional switch which includes the contents of sub-directories.

OwnerSize.bat contains:

@echo offif {%3}
{} @echo Syntax: OwnerSize Folder Owner size [/s]&goto :EOFif not exist %1 @echo Syntax: OwnerSize Folder Owner size [/s] - %1 does NOT exist.&goto :EOFsetlocal ENABLEDELAYEDEXPANSIONif exist "%TEMP%DoMath.VBS" goto calc@echo Set objArgs = WScript.Arguments>"%TEMP%DoMath.VBS"@echo wscript.echo eval(objArgs(0))>>"%TEMP%DoMath.VBS":calcset folder=%1set owner=%2set owner=%owner:"=%set /a size=0if /i {%4}
{/S} set switch=/sfor /f "Tokens=1* Delims=" %%a in ('@echo %owner%') do ( set own1=%%a set own2=%%b)if not defined own2 set own2= for /f "Tokens=1* Delims=:" %%a in ('diskuse %folder% %switch%') do ( set user=%%b if "!user:~2,9!" EQU "no domain" set user=deleted user if "%%a" EQU "User" set OK=N&for /f "Tokens=*" %%x in ('@echo !user!^|find /i "%own1%"^|find /i "%own2%"') do set OK=Y if "%%a" EQU "Space Used" if "!OK!" EQU "Y" for /f "Tokens=*" %%x in ('cscript //nologo "%TEMP%DoMath.VBS" "%%b/1048576"') do (  for /f "Tokens=*" %%y in ('cscript //nologo "%TEMP%DoMath.VBS" "%%x+!size!"') do set size=%%y ))for /f "Tokens=1* Delims=." %%a in ('@echo %size%') do ( set /a dec=%%a set frac=%%b)if "%frac:~0,1%" GTR 4 set /a dec=%dec% + 1endlocal&set /a %3=%dec%



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like