@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 ') 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
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”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.