HELP!! How to delete old folders??

A

assafm

there is a section in the "backup.bat" file i need your help with

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=
%%B.%%A.%%C
md %var%
cd C:\%var%\

those lines create a folder with today date, with a specific format
and then i use xcopy to backup the files to this folder

after X days of backuping, i have X folders on the hd, for example:
20.07.2006
21.07.2006
22.07.2006


i need to add a section that check the hd disk space
if it's less then 1 gb
then it should delete the oldest folder


i will appreciate any help,
thanks very very much
Assaf M.
 
P

Phil Robyn

there is a section in the "backup.bat" file i need your help with

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=
%%B.%%A.%%C
md %var%
cd C:\%var%\

those lines create a folder with today date, with a specific format
and then i use xcopy to backup the files to this folder

after X days of backuping, i have X folders on the hd, for example:
20.07.2006
21.07.2006
22.07.2006


i need to add a section that check the hd disk space
if it's less then 1 gb
then it should delete the oldest folder


i will appreciate any help,
thanks very very much
Assaf M.

It would be a lot easier if you named your folders according to the pattern
yyyymmdd instead of dd.mm.yyyy....
 
T

Todd Vargo

Phil Robyn said:
It would be a lot easier if you named your folders according to the pattern
yyyymmdd instead of dd.mm.yyyy....

Since the folders are created on the date they are named for, the actual
format of the names have no bearing on making it easier. Considering
recomendation to not use the root of a drive to store backups has been
ignored, removal of the separators adds additional work.

ISTM, a simple DIR command can be used to return the folders in the order
created regardless of name given. The following command will store the name
of oldest directory created (following OP's name convention).

for /f "tokens=*" %%? in ('dir c:\??.??.???? /ad/o-d/b') do set oldest=%%?


Capturing bytes free can follow similar practice.

for /f "tokens=*" %%? in ('dir c:\nul /-c') do set free=%%?
set free=%free:~23%
for /f %%? in ("%free%") do set free=%%?


Then putting the stored variables to use...

if %free% lss {limit} del/s/q %oldest%


A loop to check if deleting one directory was enough can be included.

if %free% lss {limit} %0
 
J

Jerold Schulman

there is a section in the "backup.bat" file i need your help with

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=
%%B.%%A.%%C
md %var%
cd C:\%var%\

those lines create a folder with today date, with a specific format
and then i use xcopy to backup the files to this folder

after X days of backuping, i have X folders on the hd, for example:
20.07.2006
21.07.2006
22.07.2006


i need to add a section that check the hd disk space
if it's less then 1 gb
then it should delete the oldest folder


i will appreciate any help,
thanks very very much
Assaf M.

Here are some batch scripts that will assist you.

See tip 7890 » How do I retrieve a volume's size, free space, and allocation unit, in a batch, using standard commands?
in the 'Tips & Tricks' at http://www.jsifaq.com

See tip 8293 » How can I return the date that is plus or minus n days from today?

See tip 4835 » The Universal Date Parser, modified to also work with Windows XP.

Life would be easier if your backup created

C:\BKPYYYYMMDD folders.


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 

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