Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > Computer Support > Batch File - Renaming File with DATE

Reply
Thread Tools

Batch File - Renaming File with DATE

 
 
Tom
Guest
Posts: n/a
 
      03-03-2007
Hey guys,

I have a batch file which does the following:

copy LOG.LOG LOG.txt. This creates a copy of the original with a txt
extension. But to prevent it from being overwritten the next time the
file executes, I would like it to be copied with a new name which has
the current date. So the end result will be "LOG20070303.txt"
(03/03/2007).

Is there an easy way to do this?

Thanks,

Tom.
 
Reply With Quote
 
 
 
 
Pennywise@DerryMaine.Gov
Guest
Posts: n/a
 
      03-03-2007
Tom <(E-Mail Removed)> wrote:

>Hey guys,
>
>I have a batch file which does the following:
>
>copy LOG.LOG LOG.txt. This creates a copy of the original with a txt
>extension. But to prevent it from being overwritten the next time the
>file executes, I would like it to be copied with a new name which has
>the current date. So the end result will be "LOG20070303.txt"
>(03/03/2007).
>
>Is there an easy way to do this?


Start here:

@echo off&SETLOCAL

:: This will return date into environment vars
:: Works on any NT/2K/XP machine independent of regional date
settings
:: 20 March 2002

FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call
:s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date

:s_fixdate
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof

:s_print_the_date
MD %mm%%dd%%yy%
ENDLOCAL&SET mm=%mm%&SET dd=%dd%&SET yy=%yy%

:: see also http://www.robvanderwoude.com/amb_datetime.html
:: http://www.robvanderwoude.com/datetiment.html
:: http://www.commandline.co.uk/cmdfuncs/dandt/index.htm
:: from http://www.robvanderwoude.com/index.html
--
The Logical Song
http://youtube.com/watch?v=eqwli6-RRf4
 
Reply With Quote
 
 
 
 
why?
Guest
Posts: n/a
 
      03-04-2007

On Sat, 03 Mar 2007 16:11:04 -0500, Tom wrote:

>Hey guys,
>
>I have a batch file which does the following:
>
>copy LOG.LOG LOG.txt. This creates a copy of the original with a txt
>extension. But to prevent it from being overwritten the next time the
>file executes, I would like it to be copied with a new name which has
>the current date. So the end result will be "LOG20070303.txt"
>(03/03/2007).


This will be for a MSDOS/Windows OS based system?

>Is there an easy way to do this?


Many, see past posts in 24HSHD
http://groups.google.com/group/24hou...elpdesk/topics
about batch files, many contain links to batch file sites and
newsgroups.


alt.msdos,batch
alt.msdos,batch.nt
alt.msdos,batch.win9x-me

Also
comp.lang.shell.batch.* , 3 groups

not forgetting www.google.com or even
alt.comp.freeware

It's easy in a batch file, although for the sake of neatness I used to
use a freeware exe program years ago that did the hard work of parsing
out the date / time to h:m:s d:m:d variables for you.

Me
 
Reply With Quote
 
thanatoid
Guest
Posts: n/a
 
      03-04-2007
Tom <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Hey guys,
>
> I have a batch file which does the following:
>
> copy LOG.LOG LOG.txt. This creates a copy of the original
> with a txt extension. But to prevent it from being
> overwritten the next time the file executes, I would like
> it to be copied with a new name which has the current date.
> So the end result will be "LOG20070303.txt" (03/03/2007).
>
> Is there an easy way to do this?
>
> Thanks,
>
> Tom.


"Easy way to do this" is NOT what the two prior replies provide,
IMO. I am not absolutely certain what you exactly want to do
(yes, I'm stoopid) but I am pretty sure the file manager from
www.ghisler.com can do it. I am NOT spamming, I own a copy and
it is the best. I weep for you Windows Explorer lusers.

Or you could try one of the many renaming utilities out there.

Not that there's anything wrong with simple batch files, I love
them, but they are not particularly easy to write or use for
most people.

--
Disagreements and the usual insults expected and welcomed.
 
Reply With Quote
 
why?
Guest
Posts: n/a
 
      03-04-2007

On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:

>Tom <(E-Mail Removed)> wrote in
>news:(E-Mail Removed) :
>
>> Hey guys,
>>
>> I have a batch file which does the following:
>>
>> copy LOG.LOG LOG.txt. This creates a copy of the original
>> with a txt extension. But to prevent it from being
>> overwritten the next time the file executes, I would like
>> it to be copied with a new name which has the current date.
>> So the end result will be "LOG20070303.txt" (03/03/2007).
>>
>> Is there an easy way to do this?
>>
>> Thanks,
>>
>> Tom.

>
>"Easy way to do this" is NOT what the two prior replies provide,


Explain?

>IMO. I am not absolutely certain what you exactly want to do


Exactly required is to add ymd to a filename.

It's very simple, this is the easy way -

datetime.exe
newlogfile_name = filename%y%m%d

That's all that's needed.

Rather than making the batch file longer with the working solution given
by pennywise, I said I prefer to use a free exe program, which I setup 4
years ago and can't remember the name just now.

>(yes, I'm stoopid) but I am pretty sure the file manager from
>www.ghisler.com can do it. I am NOT spamming, I own a copy and
>it is the best. I weep for you Windows Explorer lusers.


If it has a command line for use in a batch file, great, Then again the
OP could most likely find a DOS/Win cms line version of touch.exe.

>Or you could try one of the many renaming utilities out there.


Rename is 1 thing, getting the date into the rename is another.

>Not that there's anything wrong with simple batch files, I love
>them, but they are not particularly easy to write or use for
>most people.


So your point is? With a cut / paste example it's easy


OP asking for help and getting it, mind you OP didn't have to ask, just
searchiung old posts in 24hshd for my nick as the author will find
several posts with lots of links to batch scripting sites and ready to
use examples for exactly the request asked.

Me
 
Reply With Quote
 
thanatoid
Guest
Posts: n/a
 
      03-05-2007
why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
news:(E-Mail Removed):

>
> On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
>
>>Tom <(E-Mail Removed)> wrote in
>>news:(E-Mail Removed) m:
>>
>>> Hey guys,
>>>
>>> I have a batch file which does the following:
>>>
>>> copy LOG.LOG LOG.txt. This creates a copy of the original
>>> with a txt extension. But to prevent it from being
>>> overwritten the next time the file executes, I would like
>>> it to be copied with a new name which has the current
>>> date. So the end result will be "LOG20070303.txt"
>>> (03/03/2007).
>>>
>>> Is there an easy way to do this?
>>>
>>> Thanks,
>>>
>>> Tom.

>>
>>"Easy way to do this" is NOT what the two prior replies
>>provide,

>
> Explain?


I didn't read every character, but 35 lines of code is not
"easy" for most people - myself included. I SAID I'm stupid.

>>IMO. I am not absolutely certain what you exactly want to
>>do

>
> Exactly required is to add ymd to a filename.
>
> It's very simple, this is the easy way -
>
> datetime.exe
> newlogfile_name = filename%y%m%d
>
> That's all that's needed.
>
> Rather than making the batch file longer with the working
> solution given by pennywise, I said I prefer to use a free
> exe program, which I setup 4 years ago and can't remember
> the name just now.
>
>>(yes, I'm stoopid) but I am pretty sure the file manager
>>from www.ghisler.com can do it. I am NOT spamming, I own a
>>copy and it is the best. I weep for you Windows Explorer
>>lusers.

>
> If it has a command line for use in a batch file, great,


Not sure what you mean by "for use in a batch file" but it does
give you a command line with one key press. And remembers what
you did before - up to a limit you can set, IIRC.

It also has a batch-rename tool which includes the date option
and is generally better than quite a few of the specific
renamers I have tried.

> Then again the OP could most likely find a DOS/Win cms line
> version of touch.exe.
>
>>Or you could try one of the many renaming utilities out
>>there.

>
> Rename is 1 thing, getting the date into the rename is
> another.


There are so many renamers I am sure it must have occurred to
ONE of the authors to include the date as an option.

>>Not that there's anything wrong with simple batch files, I
>>love them, but they are not particularly easy to write or
>>use for most people.

>
> So your point is? With a cut / paste example it's easy


My point is I'm stoopid and I should get off the usenet.

AFA batches, using - yes, writing - no. Only Microsoft writes
their "programs" by cutting and pasting 10-20 year old code.

> OP asking for help and getting it, mind you OP didn't have
> to ask, just searchiung old posts in 24hshd for my nick as
> the author will find several posts with lots of links to
> batch scripting sites and ready to use examples for exactly
> the request asked.


That is very true - the fact that almost every question has
already been asked and answered and yet most people would rather
post again and wait than spend a few moments searching continues
to amaze me.
 
Reply With Quote
 
Rolf
Guest
Posts: n/a
 
      03-05-2007

"thanatoid" <(E-Mail Removed)> wrote in message
news:Xns98E9E66CE86C6thanexit@66.250.146.158...
> why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
> news:(E-Mail Removed):
>
> >
> > On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
> >
> >>Tom <(E-Mail Removed)> wrote in
> >>news:(E-Mail Removed) m:
> >>
> >>> Hey guys,
> >>>
> >>> I have a batch file which does the following:
> >>>
> >>> copy LOG.LOG LOG.txt. This creates a copy of the original
> >>> with a txt extension. But to prevent it from being
> >>> overwritten the next time the file executes, I would like
> >>> it to be copied with a new name which has the current
> >>> date. So the end result will be "LOG20070303.txt"
> >>> (03/03/2007).
> >>>
> >>> Is there an easy way to do this?
> >>>
> >>> Thanks,
> >>>
> >>> Tom.
> >>
> >>"Easy way to do this" is NOT what the two prior replies
> >>provide,

> >
> > Explain?

>
> I didn't read every character, but 35 lines of code is not
> "easy" for most people - myself included. I SAID I'm stupid.
>
> >>IMO. I am not absolutely certain what you exactly want to
> >>do

> >
> > Exactly required is to add ymd to a filename.
> >
> > It's very simple, this is the easy way -
> >
> > datetime.exe
> > newlogfile_name = filename%y%m%d
> >
> > That's all that's needed.
> >
> > Rather than making the batch file longer with the working
> > solution given by pennywise, I said I prefer to use a free
> > exe program, which I setup 4 years ago and can't remember
> > the name just now.
> >
> >>(yes, I'm stoopid) but I am pretty sure the file manager
> >>from www.ghisler.com can do it. I am NOT spamming, I own a
> >>copy and it is the best. I weep for you Windows Explorer
> >>lusers.

> >
> > If it has a command line for use in a batch file, great,

>
> Not sure what you mean by "for use in a batch file" but it does
> give you a command line with one key press. And remembers what
> you did before - up to a limit you can set, IIRC.
>
> It also has a batch-rename tool which includes the date option
> and is generally better than quite a few of the specific
> renamers I have tried.
>
> > Then again the OP could most likely find a DOS/Win cms line
> > version of touch.exe.
> >
> >>Or you could try one of the many renaming utilities out
> >>there.

> >
> > Rename is 1 thing, getting the date into the rename is
> > another.

>
> There are so many renamers I am sure it must have occurred to
> ONE of the authors to include the date as an option.
>
> >>Not that there's anything wrong with simple batch files, I
> >>love them, but they are not particularly easy to write or
> >>use for most people.

> >
> > So your point is? With a cut / paste example it's easy

>
> My point is I'm stoopid and I should get off the usenet.
>
> AFA batches, using - yes, writing - no. Only Microsoft writes
> their "programs" by cutting and pasting 10-20 year old code.
>
> > OP asking for help and getting it, mind you OP didn't have
> > to ask, just searchiung old posts in 24hshd for my nick as
> > the author will find several posts with lots of links to
> > batch scripting sites and ready to use examples for exactly
> > the request asked.

>
> That is very true - the fact that almost every question has
> already been asked and answered and yet most people would rather
> post again and wait than spend a few moments searching continues
> to amaze me.


I don't use 24h. very often, but I am impressed by the amount of expertise
available to me at 'just a mouse click'.

But WRT searching, I am not quite sure how I could search for a solution to
a particular problem. Maybe I am ignorant, but stupid I am not. Besides, at
76, I may be a bit lazier than most of you....

But seriously, Would it be possible to create instructions on how one may
search the forum for a particular problem solution? I don't think it is
possible to create a 'sticky' message like used on web based forums, but
what about posting the instructions on a regular basis twice a month?

Rolf


 
Reply With Quote
 
Pennywise@DerryMaine.Gov
Guest
Posts: n/a
 
      03-05-2007
"Rolf" <(E-Mail Removed)> wrote:

>But seriously, Would it be possible to create instructions on how one may
>search the forum for a particular problem solution? I don't think it is
>possible to create a 'sticky' message like used on web based forums, but
>what about posting the instructions on a regular basis twice a month?


Google archives all the text groups, this group:
http://groups.google.com/group/24hou...k/topics?hl=en

Say you have a question like oh maybe
"OE removed access to the following unsafe attachments"
(note quotes) would bring up http://tinyurl.com/3ajg5j

Main Google Group page
http://groups.google.com/grphp?ie=UT...l=en&tab=wg&q=

You use the same search operators as regular Google
http://www.google.com/intl/en/help/refinesearch.html

Some groups -not this one- supply FAQ's to answer the most common
questions http://www.faqs.org/faqs/

No Sticky notes, just bookmark the ones of interest.


--
rocky intro
http://youtube.com/watch?v=iN3azigz608
 
Reply With Quote
 
why?
Guest
Posts: n/a
 
      03-05-2007

On Mon, 5 Mar 2007 11:23:22 +0100, Rolf wrote:

>
>"thanatoid" <(E-Mail Removed)> wrote in message
>news:Xns98E9E66CE86C6thanexit@66.250.146.158...
>> why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
>> news:(E-Mail Removed):
>>
>> >
>> > On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
>> >
>> >>Tom <(E-Mail Removed)> wrote in
>> >>news:(E-Mail Removed) m:
>> >>
>> >>> Hey guys,
>> >>>
>> >>> I have a batch file which does the following:
>> >>>
>> >>> copy LOG.LOG LOG.txt. This creates a copy of the original
>> >>> with a txt extension. But to prevent it from being
>> >>> overwritten the next time the file executes, I would like


<very big snip>


>> That is very true - the fact that almost every question has
>> already been asked and answered and yet most people would rather
>> post again and wait than spend a few moments searching continues
>> to amaze me.

>
>I don't use 24h. very often, but I am impressed by the amount of expertise
>available to me at 'just a mouse click'.
>
>But WRT searching, I am not quite sure how I could search for a solution to
>a particular problem. Maybe I am ignorant, but stupid I am not. Besides, at
>76, I may be a bit lazier than most of you....
>
>But seriously, Would it be possible to create instructions on how one may
>search the forum for a particular problem solution? I don't think it is


This forum? It isn't it's a newsgroup. If you are accessing it via
http://groups.google.com/group/24hou...elpdesk/topics

There is a help page
http://groups.google.com/support/?hl=en
with a section on searching

The ultra basics are ,

- enter some appropriate words

- if too many matches prefix a wored with - , as in

dogs -hound

- If needing to search for a specific word use a +

dogs +cats


Or www.google.com and search for

google search

to see the various,

Google Image Search
Google Desktop Search
Google Blog Search
Google Book Search

Add another keyword,

google search usenet

>possible to create a 'sticky' message like used on web based forums, but
>what about posting the instructions on a regular basis twice a month?


Make your own, text file on desktop is simple enough.

>Rolf
>


Me
 
Reply With Quote
 
why?
Guest
Posts: n/a
 
      03-05-2007

On 05 Mar 2007 04:37:49 GMT, thanatoid wrote:

>why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
>news:(E-Mail Removed) :
>
>>
>> On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
>>
>>>Tom <(E-Mail Removed)> wrote in
>>>news:(E-Mail Removed) :
>>>
>>>> Hey guys,
>>>>
>>>> I have a batch file which does the following:
>>>>
>>>> copy LOG.LOG LOG.txt. This creates a copy of the original
>>>> with a txt extension. But to prevent it from being
>>>> overwritten the next time the file executes, I would like
>>>> it to be copied with a new name which has the current
>>>> date. So the end result will be "LOG20070303.txt"
>>>> (03/03/2007).
>>>>
>>>> Is there an easy way to do this?
>>>>
>>>> Thanks,
>>>>
>>>> Tom.
>>>
>>>"Easy way to do this" is NOT what the two prior replies
>>>provide,

>>
>> Explain?

>
>I didn't read every character, but 35 lines of code is not
>"easy" for most people - myself included. I SAID I'm stupid.


If it's a copy/past of a working example, problem solved. Many of the
examples from batch file sites are annotated showing how it works.

<snip>

>>>(yes, I'm stoopid) but I am pretty sure the file manager
>>>from www.ghisler.com can do it. I am NOT spamming, I own a
>>>copy and it is the best. I weep for you Windows Explorer
>>>lusers.

>>
>> If it has a command line for use in a batch file, great,

>
>Not sure what you mean by "for use in a batch file" but it does


Part of the OP request, say the filemanger you mentioned above is called

ghisler.exe

The op would put in the batch file

ghisler.exe /rename LOG.txt LOGyyyymmdd.txt

The filemanger ghisler would inset the values yyyymmdd automatically.

Opening up a filemanager and renaming the file manually would work but
it wouldn't be automated.

>give you a command line with one key press. And remembers what
>you did before - up to a limit you can set, IIRC.
>
>It also has a batch-rename tool which includes the date option
>and is generally better than quite a few of the specific
>renamers I have tried.


You just answered your question, however the tool must run with out
launching the tool and waiting for user input.

That's more in line with the example I use,

commandline-utility puts the date / time into environment varaibles
next line in batch file renames file using %yyyy %mm %dd

Not needing 35 lines of code.

<snip>

Me
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
[ANN]: 'tren' Cross-Platform Batch Renaming Tool, Version 1.217 Released Tim Daneliuk Python 0 04-26-2010 03:44 PM
Image Batch Renaming Software Advice Please bird_head Digital Photography 5 10-07-2006 08:10 AM
Help requested: renaming in batch file Pleb Plebian NZ Computing 5 01-31-2006 12:40 PM
Batch renaming in PSE 3 GrandSchtroumpf Digital Photography 0 01-07-2005 10:53 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments