IF free space on drive Z is less than nGB, delete oldest file having pattern xxx*.xxx

  • Thread starter Thread starter Frank B Denman
  • Start date Start date
F

Frank B Denman

I'm trying to figure out how to use a cmd file to test for free space on a
designated drive, and then, IF the free space is less than a specified value,
to delete the oldest (creation date) file having a particular pattern, xxx*.xxx.

This is part of a scheme to automate backing up to a rotation of large USB
drives, where each drive will be capable of holding many backups.

Much obliged for any clues, links, pointers, admonitions or other help.

Frank



Frank Denman
Denman Systems
(e-mail address removed)
Please delete the "x" from my email address.
 
Hello, Frank:
On Mon, 07 Feb 2005 22:24:09 -0800: you wrote...

FB> I'm trying to figure out how to use a cmd file to test for free space
FB> on a designated drive, and then, IF the free space is less than a
FB> specified value, to delete the oldest (creation date) file having a
FB> particular pattern, xxx*.xxx.
FB>
FB> This is part of a scheme to automate backing up to a rotation of large
FB> USB drives, where each drive will be capable of holding many backups.
FB>
FB> Much obliged for any clues, links, pointers, admonitions or other help.

Copy and paste from a working batch. Too tired to think but this is how I
did the free space thing:
setlocal ENABLEEXTENSIONS
for /f "usebackq tokens=1-10" %%a in (`dir /-p /-s /-c \\bliss\g$ ^| findstr
/i /C:" Bytes Free"`) do set FreeSpace=%%c

if %FreeSpace% LEQ 1500000000 (
echo Insufficient disk space on destination \\bliss\g$ %FreeSpace% >>
c:\logs\MoveMovies.log
goto EOF
)


Regards, Paul R. Sadowski [MVP].
 
I'm trying to figure out how to use a cmd file to test for free space on a
designated drive, and then, IF the free space is less than a specified value,
to delete the oldest (creation date) file having a particular pattern, xxx*.xxx.

This is part of a scheme to automate backing up to a rotation of large USB
drives, where each drive will be capable of holding many backups.

Much obliged for any clues, links, pointers, admonitions or other help.

It's simple with the right tools. Using 4NT:
IF %@DISKFREE[d] LT tv DEL "%@RIGHT[-10,%@EXECSTR[`FOR /A:-D /R d:\ %fn IN (xxx*.xxx) ECHO %@FILEAGE["%fn",C] %fn | SORT /R`]]"
where d is the drive to test and tv the threshold value.

Iterate to taste, like
DO WHILE %@DISKFREE[d] LT 1048576
DEL "%@RIGHT[-10,%@EXECSTR[`FOR /A:-D /R d:\ %fn IN (xxx*.xxx) ECHO %@FILEAGE["%fn",C] %fn | SORT /R`]]"
ENDDO

Note that "FOR /A:-D /R d:\ %fn IN (xxx*.xxx)" might take considerable
time. It might also fail unexpectedly if no such file exists.
For documentation see <http://jpsoft.com/help/>.
4NT is a commercial product. 4DOS, which should execute the above as
well, is free.
 
In said:
I'm trying to figure out how to use a cmd file to test for free
space on a designated drive, and then, IF the free space is
less than a specified value, to delete the oldest (creation
date) file having a particular pattern, xxx*.xxx.

This is part of a scheme to automate backing up to a rotation of
large USB drives, where each drive will be capable of holding
many backups.

Much obliged for any clues, links, pointers, admonitions or
other help.

PSINFO -d output (sysinternals) may be of assistence in determining
free space in batch ( | find and FOR token 7 (or 9) IIRC).

Volume Type Format Label Size Free Free
D: Fixed NTFS ZZZ 31.3 GB 14.1 GB 45%

Unclear on the delete part as to filenames and locations...
 
My thanks to all for the very helpful pointers.

Frank

Frank Denman
Denman Systems
(e-mail address removed)
Please delete the "x" from my email address.
 
Back
Top