PC Review


Reply
Thread Tools Rate Thread

.BAT: Delete oldest file?

 
 
(PeteCresswell)
Guest
Posts: n/a
 
      22nd Jun 2011
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?
--
PeteCresswell
 
Reply With Quote
 
 
 
 
Bob Willard
Guest
Posts: n/a
 
      22nd Jun 2011
On 6/22/2011 11:32 AM, (PeteCresswell) wrote:
> 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
--
Cheers, Bob
 
Reply With Quote
 
(PeteCresswell)
Guest
Posts: n/a
 
      22nd Jun 2011
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.
--
PeteCresswell
 
Reply With Quote
 
mm
Guest
Posts: n/a
 
      22nd Jun 2011
On Wed, 22 Jun 2011 11:32:26 -0400, "(PeteCresswell)" <(E-Mail Removed)>
wrote:

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


>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?


 
Reply With Quote
 
(PeteCresswell)
Guest
Posts: n/a
 
      22nd Jun 2011
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!!! -)
--
PeteCresswell
 
Reply With Quote
 
mm
Guest
Posts: n/a
 
      23rd Jun 2011
On Wed, 22 Jun 2011 17:35:06 -0400, "(PeteCresswell)" <(E-Mail Removed)>
wrote:

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


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


>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!!! -)


 
Reply With Quote
 
Bob Willard
Guest
Posts: n/a
 
      23rd Jun 2011
On 6/22/2011 5:35 PM, (PeteCresswell) wrote:
> 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!!! -)


You're welcome.
--
Cheers, Bob
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the oldest file in a directory. Mufasa Microsoft C# .NET 8 16th Dec 2008 10:58 AM
Compare two fields in table and delete oldest record =?Utf-8?B?U01U?= Microsoft Access VBA Modules 6 22nd Oct 2007 09:16 AM
Deleting oldest file =?Utf-8?B?U3R1Sm9s?= Microsoft Access VBA Modules 6 9th Nov 2006 03:13 PM
delete oldest dates Bart Microsoft Access Queries 4 1st Feb 2006 02:27 PM
IF free space on drive Z is less than nGB, delete oldest file having pattern xxx*.xxx Frank B Denman Microsoft Windows 2000 CMD Promt 4 11th Feb 2005 11:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:26 AM.