troubleshooting Question

Batch File [challenging and advanced]: Math to resolve "SET /a" 32bits limit

Avatar of ReneGe
ReneGeFlag for Canada asked on
Microsoft DOSProgrammingScripting Languages
65 Comments2 Solutions1083 ViewsLast Modified:
Hi there,

I scripted the following batch file.

It's purpose, is to make space for the new files to be archived to the archive drive.

I do this by comparing the working folder with it's corresponding folder in the mirror drive.

I have two problems here:
-Primero, I just came back from a very cool vacation and I'm brain challanged.
-Secundo, My archive drive is 2TB and the math involved is greater than 2147483647 bytes (32bites).

I need to make this script work considering the DOS 32bits limit.

Please remember. I'm currently brain challanged. So please do not provide ideas, but rather help me by completing my script since I need this kind of pronto.

Thanks for your help,
Rene

@ECHO OFF

SETLOCAL enabledelayedexpansion
MODE CON: COLS=150 LINES=60

REM SETTING VARIABLES
ECHO ^>SETTING VARIABLES
    SET BaseFolder=DOCS\USERSDATA
    SET BaseSource=M:
    SET BaseMirror=N:\M
    SET ArchiveDrive=O:

REM READING FILES TO BE ARCHIVED BY COMPARING THE WORKING FOLDER WITH THE MIRROR FOLDER
    SET TotalFileSize=0
    FOR /F "tokens=2 delims=	" %%A IN ('Robocopy "%BaseMirror%\%BaseFolder%" "%BaseSource%\%BaseFolder%" *.* /MIR /L /NJH /NJS /NS /NDL /XF "*RECYCLER*" "desktop.ini" "Thumbs.db" ".~*.*" "*.*#" "~*.*" "*.swp" "*.dmp" "*.tmp" "pagefile.sys" "hiberfil.sys" /XD "RECYCLER" ^| Findstr -V ^*') DO (
        SET /a TotalFileSize=!TotalFileSize! + %%~zA
    )

REM Reading free space available on archive drive
    FOR /F %%A in ('wmic logicaldisk where "DeviceID='%ArchiveDrive%'" get FreeSpace ^| FINDSTR /R [0123456789]') DO SET FreeSpace=%%A

REM Deleting old archive files up to the required space needed for the new archives
    PUSHD "%ArchiveDrive%"
    IF %FreeSpace% LEQ %TotalFileSize% (
        FOR /F "delims=" %%B IN ('DIR /s /b /od /a-d *.* ^| FINDSTR /i "%ArchiveDrive%"') DO (
            DEL /f /q "%%~fB"
            SET /a FreeSpace=!FreeSpace! + %%~zB
            ECHO !FreeSpace! %TotalFileSize% "%%~fB"
    ) ELSE (
        ECHO There is sufficient storage space available to receive the new archive files.
        ECHO Deleting old archives is not required
    )

ECHO.
PAUSE
EXIT
    
:CleanArchiveDrive
IF %FreeSpace% LEQ %TotalFileSize% EXIT /b
ECHO.
ECHO DONE
ECHO.
PAUSE
EXIT
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 65 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 65 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros