Batch File - Renaming File with DATE

Discussion in 'Computer Support' started by Tom, Mar 3, 2007.

  1. Tom

    Tom Guest

    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.
     
    Tom, Mar 3, 2007
    #1
    1. Advertising

  2. Tom

    Guest

    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).
    >
    >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
     
    , Mar 3, 2007
    #2
    1. Advertising

  3. Tom

    why? Guest

    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/24hoursupport.helpdesk/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
     
    why?, Mar 4, 2007
    #3
  4. Tom

    thanatoid Guest

    Tom <> wrote in
    news::

    > 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.
     
    thanatoid, Mar 4, 2007
    #4
  5. Tom

    why? Guest

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

    >Tom <> wrote in
    >news::
    >
    >> 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
     
    why?, Mar 4, 2007
    #5
  6. Tom

    thanatoid Guest

    why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
    news::

    >
    > On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
    >
    >>Tom <> wrote in
    >>news::
    >>
    >>> 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.
     
    thanatoid, Mar 5, 2007
    #6
  7. Tom

    Rolf Guest

    "thanatoid" <> wrote in message
    news:Xns98E9E66CE86C6thanexit@66.250.146.158...
    > why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
    > news::
    >
    > >
    > > On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
    > >
    > >>Tom <> wrote in
    > >>news::
    > >>
    > >>> 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
     
    Rolf, Mar 5, 2007
    #7
  8. Tom

    Guest

    "Rolf" <> 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/24hoursupport.helpdesk/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=UTF-8&oe=UTF-8&hl=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
     
    , Mar 5, 2007
    #8
  9. Tom

    why? Guest

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

    >
    >"thanatoid" <> wrote in message
    >news:Xns98E9E66CE86C6thanexit@66.250.146.158...
    >> why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
    >> news::
    >>
    >> >
    >> > On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
    >> >
    >> >>Tom <> wrote in
    >> >>news::
    >> >>
    >> >>> 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/24hoursupport.helpdesk/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
     
    why?, Mar 5, 2007
    #9
  10. Tom

    why? Guest

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

    >why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote in
    >news::
    >
    >>
    >> On 04 Mar 2007 20:00:54 GMT, thanatoid wrote:
    >>
    >>>Tom <> wrote in
    >>>news::
    >>>
    >>>> 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
     
    why?, Mar 5, 2007
    #10
  11. Tom

    Guest

    why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:

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


    My post was a bat file I download a long time ago, Yes it was a
    working copy, posted mainly for the Links.

    I was going to make a brain dead way for my Mom to connect her camera
    to the computer, run like copy.bat and have it move each pix from the
    camera to a directory of the days date; appending each file with the
    date as well. - how I came across the batch file.

    She found a GUI program she could understand (to an extent) and wanted
    to use that instead (just a copy from camera to a computer directory)
    so the example just sits in my INFO directory...



    --
    rocky intro
    http://youtube.com/watch?v=iN3azigz608
     
    , Mar 5, 2007
    #11
  12. Tom

    why? Guest

    On Mon, 05 Mar 2007 10:30:45 -0800, wrote:

    > why? <fgrirp*sgc@VAINY!Qznq.fpvragvfg.pbz> wrote:
    >
    >>>>>"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.

    >
    >My post was a bat file I download a long time ago, Yes it was a
    >working copy, posted mainly for the Links.
    >
    >I was going to make a brain dead way for my Mom to connect her camera
    >to the computer, run like copy.bat and have it move each pix from the
    >camera to a directory of the days date; appending each file with the
    >date as well. - how I came across the batch file.


    :) often the way of things

    I wouldn't have liked to think what the thread turned into if I posted
    the perl script I use many times to do the samething,


    Oh and found the app, I used before,
    http://www.computing.net/faq/contentdos/datetime.html


    <snip>

    Me
     
    why?, Mar 5, 2007
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    3,181
  2. GrandSchtroumpf

    Batch renaming in PSE 3

    GrandSchtroumpf, Jan 7, 2005, in forum: Digital Photography
    Replies:
    0
    Views:
    352
    GrandSchtroumpf
    Jan 7, 2005
  3. Replies:
    1
    Views:
    1,323
    Digital Photography Now
    Oct 4, 2005
  4. bird_head

    Image Batch Renaming Software Advice Please

    bird_head, Oct 7, 2006, in forum: Digital Photography
    Replies:
    5
    Views:
    465
    Pete D
    Oct 7, 2006
  5. Pleb Plebian

    Help requested: renaming in batch file

    Pleb Plebian, Jan 31, 2006, in forum: NZ Computing
    Replies:
    5
    Views:
    416
    ~misfit~
    Jan 31, 2006
Loading...

Share This Page