Page 1 of 1

Purge Disk When Full Dos Batch Files Windows XP pro

Posted: 19 Jun 2010 14:50
by metallica1973
I have created a batch script that copies all information to an external hdd. I need help creating a script that will tell me when that external HDD is almost full and to start deleting the oldest backup directories from the external hdd

Code: Select all

@ECHO OFF
echo d|XCOPY C:\DOCUME~1\Cozed\MYDOCU~1\* E:\Daily\%date:~4,2%_%date:~7,2%_%date:~10,4%_Data /y /s /v
echo d|XCOPY C:\DOCUME~1\Cozed\applic~1\thunde~1\* E:\Daily\%date:~4,2%_%date:~7,2%_%date:~10,4%_Email /y /s /v


So I want to add this function to this script of deleting the oldest backup directory on the external when it is full. This would be the E: drive (attached external hdd)Help?

Re: Purge Disk When Full Dos Batch Files Windows XP pro

Posted: 19 Jun 2010 16:13
by aGerman
Hmm, it's not that easy because you can only get the free space in bytes. On big drives this value can be too high to calculate it or to compare it as number using batch.
OK, first two snippets:

Code: Select all

for /f "tokens=3" %%i in ('dir /-c E:\') do set "free=%%i"
echo %free%

This should return the free space of drive E:\ in bytes.

Code: Select all

for /f "delims=" %%i in ('dir /ad /b /o-n E:\Daily') do set "oldest=%%i"
echo %oldest%

This should return the oldest folder in E:\Daily matched by the folder name (if you would change the names beginning with YYYYMMDD). Otherwise you could use the switch /o-d or (only on NTFS formatted drives) /t-c.

Well, the question is how much free space would you need for a backup and how much capacity has the drive (is it more than 4,294,967,295 bytes)?

Regards
aGerman