Batch File Programming

Batch File Programming

Post by Sarah » Wed, 12 Jan 2005 04:59:35

I was hoping someone may be able to offer some assistance. I need to copy
the same file each day via a batch file to a new location to store as an
archive. The problem is I can only figure out how to rename it once in a bat
file. (Ex ren file.1 to file.2)

What I would like to do is to copy the file and have the date appended to
the file name (example: file.1 would either become DDMMYY.1 or file.DDMMYY).

Basically I need a way to not overwite the existing archive and name the new
one in a way that is unique, but have it happen automatically. Is there a
way this can be done via a batch file? Any examples would be helpful as my
programming skilles are minimal.

Many thanks in advance.

Batch File Programming

Post by Gary Chans » Wed, 12 Jan 2005 08:02:12


I can't think of a way to do this in a batch file run by CMD.exe without
running into various limitations but it would be trivial to do in a batch
file run by my QExec program. If you'd like to try it, it's available at

-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)


Batch File Programming

Post by anonymou » Wed, 12 Jan 2005 10:19:32

I need to copy
to store as an
rename it once in a bat
date appended to
DDMMYY.1 or file.DDMMYY).


Use "set /?" to get more information on dynamic environment
variables. (Command line extensions must be enabled.)

Batch File Programming

Post by Dr John St » Thu, 13 Jan 2005 02:26:35

JRS: In article <euoPO# XXXX@XXXXX.COM >, dated Mon, 10

Sarah M < XXXX@XXXXX.COM > posted :

Assuming that you have WSH and javascript, which seems likely, and that
it is safe to use filenames ~tmp.*, the following batch file will load
environment variable YYYYMMDD with ... the date YYYYMMDD. It could be
adapted to use VBS instead.

@echo off
echo var D = new Date() > ~tmp.js
echo D = (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate() >> ~tmp.js
echo WScript.Echo( 'set YYYYMMDD='+D ) >> ~tmp.js
echo @echo off > ~tmp.bat
cscript //nologo ~tmp.js >> ~tmp.bat
del ~tmp.js
call ~tmp
del ~tmp.bat

The rest is easy enough.

Pure Win98 batch cannot do it, though one can use my NOWMINUS, via sig
line 3.

However, there is probably a solution within the batch language proper,

John Stockton, Surrey, UK. ? DOS 3.3, 6.20; Win98. Web< >/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via< ;m>
My DOS< ;m> - also batprogs.htm.