PC Review


Reply
Thread Tools Rate Thread

Create unique filename - datetimestamp

 
 
Cliff Cotterill
Guest
Posts: n/a
 
      17th Mar 2005
How do you create a unique filename in a batch file?
Can the TIME /t and DATE /t be concatenated to a filename variable?



 
Reply With Quote
 
 
 
 
Phil Robyn
Guest
Posts: n/a
 
      17th Mar 2005
Cliff Cotterill wrote:

> How do you create a unique filename in a batch file?
> Can the TIME /t and DATE /t be concatenated to a filename variable?
>
>
>

- - - - - - - - - - begin screen capture WinXP - - - - - - - - - -
C:\cmd>demo\Timestamp123
20050317112924

C:\cmd>rlist demo\Timestamp123.cmd
=====begin C:\cmd\demo\Timestamp123.cmd ====================
1. @echo off
2. setlocal
3. for /f "tokens=2-4 delims=/ " %%a in (
4. 'date /t'
5. ) do set zdate=%%c%%a%%b
6. for /f "tokens=5-7 delims=:. " %%a in (
7. 'echo/^|time^|find "current"'
8. ) do set ztime=%%a%%b%%c
9. echo %zdate%%ztime%
=====end C:\cmd\demo\Timestamp123.cmd ====================
- - - - - - - - - - end screen capture WinXP - - - - - - - - - -

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
 
Reply With Quote
 
Torgeir Bakken \(MVP\)
Guest
Posts: n/a
 
      17th Mar 2005
Cliff Cotterill wrote:

> How do you create a unique filename in a batch file?
> Can the TIME /t and DATE /t be concatenated to a filename variable?

Hi

One way is to from your batch file create a temporary vbscript
file on the fly and pick up the result, more here:

http://groups.google.co.uk/groups?se...TNGP09.phx.gbl

and
http://www.jsiinc.com/SUBR/tip8600/rh8600.htm


You can do it with "pure" batch file as well, using e.g the batch date
time functions from Ritchie Lawrence batch library available at
http://www.commandline.co.uk/lib


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scr...r/default.mspx
 
Reply With Quote
 
Al Dunbar [MS-MVP]
Guest
Posts: n/a
 
      18th Mar 2005

"Torgeir Bakken (MVP)" <Torgeir.Bakken-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Cliff Cotterill wrote:
>
> > How do you create a unique filename in a batch file?
> > Can the TIME /t and DATE /t be concatenated to a filename variable?

> Hi
>
> One way is to from your batch file create a temporary vbscript
> file on the fly and pick up the result, more here:
>
>

http://groups.google.co.uk/groups?se...TNGP09.phx.gbl
>
> and
> http://www.jsiinc.com/SUBR/tip8600/rh8600.htm
>
>
> You can do it with "pure" batch file as well, using e.g the batch date
> time functions from Ritchie Lawrence batch library available at
> http://www.commandline.co.uk/lib


A filename derived from the time and date is only guaranteed to be unique
if:

- the clock is never turned back, and if:
- such files are NEVER created outside of the script that uses the feature.

I would tend to add a random field (a la %random%), and check for existence
before assuming otherwise. If the file already existed, the script would
just re-build the name and try again.

/Al


 
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
Saving to a Unique Filename =?Utf-8?B?cmFuZHkxMjAw?= Microsoft C# .NET 3 14th Sep 2007 09:03 PM
Outputting to a unique filename Aaron Howe Microsoft Access 8 12th Jan 2005 02:21 PM
Unique Backup Filename Redux AA Microsoft Word Document Management 3 8th Jun 2004 02:39 AM
Unique Backup Filename, Not AA Microsoft Word Document Management 15 31st May 2004 04:31 PM
how to create unique filename in a specified folder ??? Antonio Lopez Arredondo Microsoft Dot NET 1 29th Nov 2003 11:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:35 PM.