.BAT: Delete oldest file?

P

(PeteCresswell)

I've got a .BAT routine that keeps 30 backup copies of a file.

Right now, I am just naming them

Whatever.00
Whatever.01
Whatever.02....
Whatever.30

Then, when it is time to run an new backup, I just delete
Whatever.00, rename Whatever.01 to Whatever.00, rename
Whatever.02 to Whatever.01 - and so-forth, making the new backup
Whatever.30.

Works, but it would be a lot nicer if I could name the files with
a timestamp instead of a two-digit number.

e.g.

Whatever.2011.06-01
Whatever.2011.06-02
Whatever.2011.06-03....
Whatever.2011.06-30

Creating the file name sb no problem.

But how to identify the oldest file before creating the latest
one?

Seems like I could either scan the file names (sounds pretty
intimidating to me...), scan the props (also intimidating).

What I'm trolling for is some BAT or CMD command that will
magically return the oldest file.

Anybody?
 
B

Bob Willard

I've got a .BAT routine that keeps 30 backup copies of a file.

Right now, I am just naming them

Whatever.00
Whatever.01
Whatever.02....
Whatever.30

Then, when it is time to run an new backup, I just delete
Whatever.00, rename Whatever.01 to Whatever.00, rename
Whatever.02 to Whatever.01 - and so-forth, making the new backup
Whatever.30.

Works, but it would be a lot nicer if I could name the files with
a timestamp instead of a two-digit number.

e.g.

Whatever.2011.06-01
Whatever.2011.06-02
Whatever.2011.06-03....
Whatever.2011.06-30

Creating the file name sb no problem.

But how to identify the oldest file before creating the latest
one?

Seems like I could either scan the file names (sounds pretty
intimidating to me...), scan the props (also intimidating).

What I'm trolling for is some BAT or CMD command that will
magically return the oldest file.

Anybody?

Just my opinion, but I think you are signing up for complexity without
value. Remember that the timestamp(s) of the file are attributes which
are visible from WinExplorer and from DOS already, so I suggest that you
keep your current naming scheme.

A better solution would be to use a filesystem that supports versioning,
but it seems that such a 25-year old scheme is beyond the current
capabilities of our friends in Seattle. :p
 
P

(PeteCresswell)

Per Bob Willard:
Just my opinion, but I think you are signing up for complexity without
value. Remember that the timestamp(s) of the file are attributes which
are visible from WinExplorer and from DOS already, so I suggest that you
keep your current naming scheme.

Thanks for saving me from myself..... -)

I got off on this when I saw that CreatedAt was the same for all
the files in my test - which seemed logical in light of my
renaming all the existing files before backing up the latest.

But, now that I am looking at ModifiedAt instead, I find that
reflects the actual creation timestamp - and that does it for me.

Thanks again.
 
M

mm

I've got a .BAT routine that keeps 30 backup copies of a file.

Right now, I am just naming them

Whatever.00
Whatever.01
Whatever.02....
Whatever.30

Then, when it is time to run an new backup, I just delete
Whatever.00, rename Whatever.01 to Whatever.00, rename
Whatever.02 to Whatever.01 - and so-forth, making the new backup
Whatever.30.

Works, but it would be a lot nicer if I could name the files with
a timestamp instead of a two-digit number.

e.g.

Whatever.2011.06-01
Whatever.2011.06-02
Whatever.2011.06-03....
Whatever.2011.06-30

Creating the file name sb no problem.

But how to identify the oldest file before creating the latest
one?

Hi, Pete. Why do you have to identify the oldest? If you create the
latesst with the current data and time, won't that be enough to make
the names different, and sort in the right order?

I wrote a short routine that names the files after the current date
and time, if you want it. I"m sure there are plenty of others.
 
P

(PeteCresswell)

Per mm:
Hi, Pete. Why do you have to identify the oldest? If you create the
latesst with the current data and time, won't that be enough to make
the names different, and sort in the right order?

I only keep the most recent 30 copies - so I need to delete the
oldest one each time.

That was easy with naming convention *.00*, *.01*, and so-forth.

But I wanted the list of files that comes up in Windows Explorer
tb identifiable by date - and jumped to the conclusion that
embedding the date in the file names was the right thing to do -
having seen that "Created Date" kept coming up the same.


Bob Willard, however, brought me to my senses. I looked again,
and found that "Date Modified" contained the original creation
date - even after the file had been renamed a few times.

Bottom line, there's no need for me do what I was going to do.

Thank goodness!!! -)
 
M

mm

Per mm:

I only keep the most recent 30 copies - so I need to delete the
oldest one each time.

For the record, witih XXCOPY ,a free for personal use or maybe totally
free DOS program, I don't know that you can delete the oldest (but
maybe, there are so many options I can't learn them all)

but what you can do is delete anything of a certain style name that is
more than 30 days old, for example. Like everything named *.txt or
text*.txt, or whatever. )
 
B

Bob Willard

Per mm:

I only keep the most recent 30 copies - so I need to delete the
oldest one each time.

That was easy with naming convention *.00*, *.01*, and so-forth.

But I wanted the list of files that comes up in Windows Explorer
tb identifiable by date - and jumped to the conclusion that
embedding the date in the file names was the right thing to do -
having seen that "Created Date" kept coming up the same.


Bob Willard, however, brought me to my senses. I looked again,
and found that "Date Modified" contained the original creation
date - even after the file had been renamed a few times.

Bottom line, there's no need for me do what I was going to do.

Thank goodness!!! -)

You're welcome.
 

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