David Trimboli said:
We've got a series of roaming profiles on \\server\profiles$ , and
they're asking me to get the total size of all Desktop folders (in
preparation for deploying Desktop Folder Redirection). I'm looking for
a quick way to determine this number. The script is proving trickier
than I'd thought. Any advice?
Thanks for everyone's help so far. I'm getting some strange behavior
with what I've got so far. Can anyone explain what's going on?
Some background: we have two profiles shares: \\server\profiles$ and
\\server\profile$. Each profile share is populated with roaming
profiles: directories of eight characters or less, with no spaces, the
same as each user name. I have full access to all shares, directories,
and files.
Here's the script as it stands now (names have been changed to protect
the innocent):
=======================
local
set size=0
call :FindDesktopSize \\server\profiles$
call :findDesktopSize \\server\profile$
echo %size% bytes
goto :EOF
:GetSize
REM Call this subroutine with a directory as the only parameter.
REM Find the size of the files in it in bytes (not including
subdirectories).
REM Add this to the variable SIZE.
for /f "tokens=3" %%i in ('dir /-c "%1" ^| find "File(s)"') do (
set /a size+=%%i
)
goto :EOF
ushDir
REM Call this subroutine with a directory as the only parameter.
REM Push into this directory, call GetSize, then push into each
subdirectory
REM (make a recursive call to this subroutine). Finally, pop out of the
REM directory.
pushd "%1"
call :GetSize .
for /d %%i in (*) do call
ushDir "%%i"
popd
goto :EOF
:FindDesktopSize
REM Call this subroutine with a profile share as the only parameter. Get
a list
REM of directories in the share, then PushDir against each
REM share\directory\desktop.
for /d %%i in (%1\*) do call
ushDir %%i\desktop
:goto EOF
==========================
Here's some sample output (same note about names):
============================
H>size.cmd
H>setlocal
H>set size=0
H>call :FindDesktopSize \\server\profiles$
H>REM Call this subroutine with a profile share as the only parameter.
Get a list
H>REM of directories in the share, then PushDir against each
H>REM share\directory\desktop.
H>for / %i in (\\server\profiles$\*) do call
ushDir %i\desktop
H>call
ushDir \\server\profiles$\user1\desktop
H>REM Call this subroutine with a directory as the only parameter.
H>REM Push into this directory, call GetSize, then push into each
subdirectory
H>REM (make a recursive call to this subroutine). Finally, pop out of
the
H>REM directory.
H>pushd "\\server\profiles$\user1\desktop"
Y>call :GetSize .
Y>REM Call this subroutine with a directory as the only parameter.
Y>REM Find the size of the files in it in bytes (not including
subdirectories).
Y>REM Add this to the variable SIZE.
Y>for /F "tokens=3" %i in ('dir /-c "." | find "File(s)"') do (set /a
size+=%i )
Y>(set /a size+=5225237 )
Y>goto :EOF
Y>for / %i in (*) do call
ushDir "%i"
Y>popd
H>goto :EOF
H>call
ushDir \\server\profiles$\user2\desktop
H>REM Call this subroutine with a directory as the only parameter.
H>REM Push into this directory, call GetSize, then push into each
subdirectory
H>REM (make a recursive call to this subroutine). Finally, pop out of
the
H>REM directory.
H>pushd "\\server\profiles$\user2\desktop"
Y>call :GetSize .
Y>REM Call this subroutine with a directory as the only parameter.
Y>REM Find the size of the files in it in bytes (not including
subdirectories).
Y>REM Add this to the variable SIZE.
Y>for /F "tokens=3" %i in ('dir /-c "." | find "File(s)"') do (set /a
size+=%i )
Y>(set /a size+=5225237 )
Y>goto :EOF
Y>for / %i in (*) do call
ushDir "%i"
Y>popd
H>goto :EOF
H>call
ushDir \\server\profiles$\user3\desktop
H>REM Call this subroutine with a directory as the only parameter.
H>REM Push into this directory, call GetSize, then push into each
subdirectory
H>REM (make a recursive call to this subroutine). Finally, pop out of
the
H>REM directory.
H>pushd "\\server\profiles$\user3\desktop"
Y>call :GetSize .
Y>REM Call this subroutine with a directory as the only parameter.
Y>REM Find the size of the files in it in bytes (not including
subdirectories).
Y>REM Add this to the variable SIZE.
Y>for /F "tokens=3" %i in ('dir /-c "." | find "File(s)"') do (set /a
size+=%i )
Y>(set /a size+=5225237 )
Y>goto :EOF
Y>for / %i in (*) do call
ushDir "%i"
Y>popd
H>goto :EOF
=======================
....etc...
Notice how size is always incremented by 5225237 bytes? I don't
understand why this is. (I'm not sure what directory I may have that is
exactly that size.) I've also seen elsewhere in the output that Desktop
subdirectories are being pushed to correctly, but still the wrong value
of 5225237 is what is added to SIZE.
I do notice that the FOR command from the PushDir subroutine is getting
its "/D" chopped into "/". Why is this?