HELP: Need to insert current date into file name using Win batch scripting.

JPS

Golden Member
Apr 23, 2001
1,745
0
71
I use simple windows batch scripting to automate some software development I do. The one thing that is hanging me up is the final step where I zip all the files up into a self-extracter. I want to be able to insert the current date into the resulting file's name. I am using Z-7ip to make the self-extractor and this is a snippet of the code at that point in the script:
cd D:\
"C:\Program Files\7-Zip\7z.exe" a -sfx7zC.sfx -r -mx9 -m0=LZMA:mf=bt4b:D=32M:fb=139:a=2 -ms=on -mf=on -mhcf=on -mhc=off newarchive_v2.exe archives\*
Right now I have to go back after the script finishes and change the name newarchive_v2.exe to newarchive_20040820_v2.exe. How can automate this process so that the batch file that makes the .exe file can insert the date into the name of the resulting .exe file? Also, I want the format to be YYYYMMDD for the date part of the name.

Thanks in advance for your help!!!!
 

JPS

Golden Member
Apr 23, 2001
1,745
0
71
Originally posted by: KLin
this will probably work in vbscript.

Thanks much, but I am working on the Windows command line using the "DOS" like commands there. I want to find a command from within that environment that will accomplish what I am after.
 

KLin

Lifer
Feb 29, 2000
30,052
459
126
Originally posted by: JPS
Originally posted by: KLin
this will probably work in vbscript.

Thanks much, but I am working on the Windows command line using the "DOS" like commands there. I want to find a command from within that environment that will accomplish what I am after.

you can execute the vbscript from a command line. Save that code as a vbs file, then put a line in your batch script like "csript c:\zipfile.vbs" or something to that effect. I don't know if it'll work or not :)
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: JPS
Originally posted by: KLin
this will probably work in vbscript.

Thanks much, but I am working on the Windows command line using the "DOS" like commands there. I want to find a command from within that environment that will accomplish what I am after.

If you save KLin's code as a .vbs file, you can execute from the command line by running "cscript <name>.vbs"

EDIT: Too slow :)
 

JPS

Golden Member
Apr 23, 2001
1,745
0
71
O.K. I saved the script to test.vbs and changed to script to go

cd: D:\
cscript D:\Dev\test.vbs

But I get this error: D:\dev\test.vbs(3, 44) Microsoft VBScript compilation error: Expected end of statement

So I removed the offending " at position 44 and now get this error:
D:\dev\test.vbs(3, 1) Microsoft VBScript runtime error: Type mismatch: 'format'

Here is the command as it stands right now:
oShell.run "C:\Program Files\7-Zip\7z.exe a -sfx7zC.sfx -r -mx9 -m0=LZMA:mf=bt4b=32M:fb=139:a=2 -ms=on -mf=on -mhcf=on -mhc=off &amp; format(Now(), "YYYYMMDD") &amp; "-" &amp; "newarchive_v2.exe archives\*"

I do not know vbs so any more help would be appreciated...
 

KLin

Lifer
Feb 29, 2000
30,052
459
126
Originally posted by: JPS
O.K. I saved the script to test.vbs and changed to script to go

cd: D:\
cscript D:\Dev\test.vbs

But I get this error: D:\dev\test.vbs(3, 44) Microsoft VBScript compilation error: Expected end of statement

So I removed the offending " at position 44 and now get this error:
D:\dev\test.vbs(3, 1) Microsoft VBScript runtime error: Type mismatch: 'format'

Here is the command as it stands right now:
oShell.run "C:\Program Files\7-Zip\7z.exe a -sfx7zC.sfx -r -mx9 -m0=LZMA:mf=bt4b=32M:fb=139:a=2 -ms=on -mf=on -mhcf=on -mhc=off &amp; format(Now(), "YYYYMMDD") &amp; "-" &amp; "newarchive_v2.exe archives\*"

I do not know vbs so any more help would be appreciated...

woops, the format function is not a valid function for vbscript. try this one instead: