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

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.
 
P

Paul R. Sadowski [MVP]

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].
 
M

Michael Bednarek

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.
 
M

Mark V

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...
 
F

Frank B Denman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top