Go Back   Technology Questions > Software Questions > Operating System Questions > Windows XP

Windows XP Discuss the Microsoft Windows XP Operating System

Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 01-04-2007, 06:18 AM
simonc
Tablet PC Guest
 
Posts: n/a
Rename in a batch file

This is a batch programming issue, so I'm not sure if this is the right
newsgroup. If not, maybe someone could suggest a better one.

In a batch file which runs a backup I want the last line to rename the log
file

name_of_backup_job.txt to

name_of_backup_job_today's date.txt with the date in YMD format so that
files will sort into order properly in a directory listing.

How do I extract the date into a variable, and how can I get it into YMD
format?

Grateful for advice.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

 
Old 01-04-2007, 06:18 AM
Xploder HD Movie Player for PS3. Manage, convert and transfer media files between the PC and PS3.
  #2 (permalink)  
Old 01-04-2007, 06:18 AM
Pegasus \(MVP\)
Tablet PC Guest
 
Posts: n/a
Re: Rename in a batch file


"simonc" <simonc@discussions.microsoft.com> wrote in message
news:46F83B7E-DDE0-4A81-A0AF-A2C2790C3FAF@microsoft.com...
> This is a batch programming issue, so I'm not sure if this is the right
> newsgroup. If not, maybe someone could suggest a better one.
>
> In a batch file which runs a backup I want the last line to rename the log
> file
>
> name_of_backup_job.txt to
>
> name_of_backup_job_today's date.txt with the date in YMD format so that
> files will sort into order properly in a directory listing.
>
> How do I extract the date into a variable, and how can I get it into YMD
> format?
>
> Grateful for advice.


I suspect you don't mean YMD format but perhaps YYYYMMDD.
You can do it like this:

@echo off
set D=%date:~6,4%%date:~0,2%%date:~3,2%
echo ren name_of_backup_job.txt name_of_backup_job_%D%.txt

Remove the "echo" word to activate the batch file.
Depending on your time zone and data format, you
may have to tune the numbers in the second line.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 01-04-2007, 06:18 AM
Pegasus \(MVP\)
Tablet PC Guest
 
Posts: n/a
Re: Rename in a batch file


"simonc" <simonc@discussions.microsoft.com> wrote in message
news:46F83B7E-DDE0-4A81-A0AF-A2C2790C3FAF@microsoft.com...
> This is a batch programming issue, so I'm not sure if this is the right
> newsgroup. If not, maybe someone could suggest a better one.
>
> In a batch file which runs a backup I want the last line to rename the log
> file
>
> name_of_backup_job.txt to
>
> name_of_backup_job_today's date.txt with the date in YMD format so that
> files will sort into order properly in a directory listing.
>
> How do I extract the date into a variable, and how can I get it into YMD
> format?
>
> Grateful for advice.


I suspect you don't mean YMD format but perhaps YYYYMMDD.
You can do it like this:

@echo off
set D=%date:~6,4%%date:~0,2%%date:~3,2%
echo ren name_of_backup_job.txt name_of_backup_job_%D%.txt

Remove the "echo" word to activate the batch file.
Depending on your time zone and data format, you
may have to tune the numbers in the second line.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 01-04-2007, 06:18 AM
simonc
Tablet PC Guest
 
Posts: n/a
Re: Rename in a batch file

Brilliant. Thank you very much. That does exactly what I wanted.

"Pegasus (MVP)" wrote:

>
> "simonc" <simonc@discussions.microsoft.com> wrote in message
> news:46F83B7E-DDE0-4A81-A0AF-A2C2790C3FAF@microsoft.com...
> > This is a batch programming issue, so I'm not sure if this is the right
> > newsgroup. If not, maybe someone could suggest a better one.
> >
> > In a batch file which runs a backup I want the last line to rename the log
> > file
> >
> > name_of_backup_job.txt to
> >
> > name_of_backup_job_today's date.txt with the date in YMD format so that
> > files will sort into order properly in a directory listing.
> >
> > How do I extract the date into a variable, and how can I get it into YMD
> > format?
> >
> > Grateful for advice.

>
> I suspect you don't mean YMD format but perhaps YYYYMMDD.
> You can do it like this:
>
> @echo off
> set D=%date:~6,4%%date:~0,2%%date:~3,2%
> echo ren name_of_backup_job.txt name_of_backup_job_%D%.txt
>
> Remove the "echo" word to activate the batch file.
> Depending on your time zone and data format, you
> may have to tune the numbers in the second line.
>
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 01-04-2007, 06:18 AM
simonc
Tablet PC Guest
 
Posts: n/a
Re: Rename in a batch file

Brilliant. Thank you very much. That does exactly what I wanted.

"Pegasus (MVP)" wrote:

>
> "simonc" <simonc@discussions.microsoft.com> wrote in message
> news:46F83B7E-DDE0-4A81-A0AF-A2C2790C3FAF@microsoft.com...
> > This is a batch programming issue, so I'm not sure if this is the right
> > newsgroup. If not, maybe someone could suggest a better one.
> >
> > In a batch file which runs a backup I want the last line to rename the log
> > file
> >
> > name_of_backup_job.txt to
> >
> > name_of_backup_job_today's date.txt with the date in YMD format so that
> > files will sort into order properly in a directory listing.
> >
> > How do I extract the date into a variable, and how can I get it into YMD
> > format?
> >
> > Grateful for advice.

>
> I suspect you don't mean YMD format but perhaps YYYYMMDD.
> You can do it like this:
>
> @echo off
> set D=%date:~6,4%%date:~0,2%%date:~3,2%
> echo ren name_of_backup_job.txt name_of_backup_job_%D%.txt
>
> Remove the "echo" word to activate the batch file.
> Depending on your time zone and data format, you
> may have to tune the numbers in the second line.
>
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename in a batch file simonc Windows XP 0 01-04-2007 06:18 AM
Batch File Victor Windows XP 14 01-04-2007 06:18 AM
Batch file help MSBhhNish Windows XP 9 01-04-2007 04:43 AM
how to execute batch file automatically when file is added in folder SANDY Windows XP 4 01-04-2007 03:48 AM


All times are GMT -8. The time now is 03:29 AM.


2003 - 2008 All Rights Reserved. Technology Questions

SEO by vBSEO 3.1.0