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


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

NOTE: OwnerSize.bat uses DiskUse.exe.

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 Settings\Jerry", or D:.

Owner   is the owner, like BUILTIN\Administrators or JSIINC\Jerry or JSI009\Jerry.
        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 call directed numeric environment variable that will contain the size in megabytes.

/S      is an optional switch which includes the contents of sub-directories.
OwnerSize.bat contains:
@echo off
if \{%3\}

\{\} @echo Syntax: OwnerSize Folder Owner size \[/s\]&goto :EOF if not exist %1 @echo Syntax: OwnerSize Folder Owner size \[/s\] - %1 does NOT exist.&goto :EOF setlocal ENABLEDELAYEDEXPANSION if exist "%TEMP%\DoMath.VBS" goto calc @echo Set objArgs = WScript.Arguments>"%TEMP%\DoMath.VBS" @echo wscript.echo eval(objArgs(0))>>"%TEMP%\DoMath.VBS" :calc set folder=%1 set owner=%2 set owner=%owner:"=% set /a size=0 if /i \{%4\}

\{/S\} set switch=/s for /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% + 1 endlocal&set /a %3=%dec%



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish