Solved Warn if directory size too large

July 11, 2012 at 06:55:24
Specs: Windows 7
What i am trying to do is check the size of 2 directories and see if combined they are 1 MB or larger. If they are too large the user wil receive a message and if not it will jump to eof. For some reason it does not want to work for me so could someone who is better at scripting take a look at it?

@echo off & setLocal enableDELAYedeXpansioN


for /f "tokens=* delims= " %%a in ('dir/b "C:\Users\%username%\Desktop"') do (
set /A size /=1048576
)
if (!size!)==(0) goto :eof
msg * !size! Mb or greater used on your profile. Please place documents in your Home Folder, not on your Desktop.

for /f "tokens=* delims= " %%a in ('dir/b "C:\Users\%username%\Documents"') do (
set /A size /=1048576
)
if (!size!)==(0) goto :eof
msg * !size! Mb or greater used on your profile. Please place documents in your Home Folder, not in your Documents.

:eof


See More: Warn if directory size too large

Report •

#1
July 11, 2012 at 08:34:06
Managed to find somewhat of a solution to my problem. What i am aiming to accomplish is adding the file sizes together and judging the outcome.

@echo off
setlocal
set fileb="C:\Users\%username%\Desktop"
set filea="C:\Users\%username%\Documents"
set maxbytesize=262144

FOR /F "usebackq" %%A IN ('%filea%') DO set sizea=%%~zA

if %sizea% LSS %maxbytesize% (
echo.File is ^< %maxbytesize% bytes


) ELSE (
msg * Your profile has exceeded maximum capacity. Please place documents in your Home Folder, not in your Documents.
)


FOR /F "usebackq" %%A IN ('%fileb%') DO set sizeb=%%~zA

if %sizeb% LSS %maxbytesize% (
echo.File is ^< %maxbytesize% bytes


) ELSE (
msg * Your profile has exceeded maximum capacity. Please place documents in your Home Folder, not on your Desktop.
)


Report •

#2
July 11, 2012 at 20:32:22
✔ Best Answer
(kind-of stingy with disk-space, aren't we? my god, 2mb? one floppy holds half that, Lol!)
Try this:
@echo off
setlocal
set maxbytesize=262144
set ttlsize=0
for %%z in ("C:\Users\%username%\Desktop","C:\Users\%username%Documents") do (
:optional debugging/info stuff
echo dir & size: %%z %%~zz
set /a ttlsize+=%%~zz
)
echo you've used %ttlsize% out of %maxbytesize%
if %ttlsize% lss %maxbytesize% goto :eof
echo BLAAA!!! BLAA!!! BLAA!!
DANGER WILL ROBINSON! YOU ARE IN VIOLATION OF LOCAL RESTRICTIONS!
:end

not tested. My win-7 is sleeping and i didn't want to wake him up to try this. xp doesn't seem to deliver file-sizes-totals when analyzing a directory, I got zeros.


Report •

#3
July 12, 2012 at 05:40:59
Its Citrix. When you pull a profile over a T1 from philly to florida it kinda takes a while if the profile isnt super small. I do however appreciate the help immensely thank you!

Report •
Related Solutions


Ask Question