Command prompt :: create file

P

Peter CCH

Is there anyway to create a file with the current date as the file name
by using command prompt?

Actually I'd schedule a task to run every night to compress some file
using WinRAR.

I'm using this:
c:\winrar\winrar.exe a -r "c:\afterCompress.rar"
"c:\toBeCompressedFolder"

But if it's possible, I would like to make the "c:\afterCompress.rar"
to be "c:\afterCompress-date.rar" which the '-date' would be the system
date when the folder is compressed.

Any idea?


Thanks.
 
G

Guest

Hi,

Have you tried to select in winrar, in the tab - backup - Generate archive
name by mask?

I think that will solve your problem.
 
P

Pegasus \(MVP\)

Peter CCH said:
Is there anyway to create a file with the current date as the file name
by using command prompt?

Actually I'd schedule a task to run every night to compress some file
using WinRAR.

I'm using this:
c:\winrar\winrar.exe a -r "c:\afterCompress.rar"
"c:\toBeCompressedFolder"

But if it's possible, I would like to make the "c:\afterCompress.rar"
to be "c:\afterCompress-date.rar" which the '-date' would be the system
date when the folder is compressed.

Any idea?


Thanks.

Try this:

@echo off
set MyDate=%date:/=-%
c:\winrar\winrar.exe a -r "c:\afterCompress %MyDate%.rar"
"c:\toBeCompressedFolder"

This works if your date delimiter consists of slashes.
 
T

Torgeir Bakken \(MVP\)

Peter said:
Is there anyway to create a file with the current date as the file name
by using command prompt?

Actually I'd schedule a task to run every night to compress some file
using WinRAR.

I'm using this:
c:\winrar\winrar.exe a -r "c:\afterCompress.rar"
"c:\toBeCompressedFolder"

But if it's possible, I would like to make the "c:\afterCompress.rar"
to be "c:\afterCompress-date.rar" which the '-date' would be the system
date when the folder is compressed.
Hi,

You could use the code below in your batch file.

It is using the ISO 8601 date format yyyy-mm-dd so it is unambiguous
and easily sortable in Explorer.


--------------------8<----------------------
echo D = Now : WScript.Echo Year(D) ^& "-" ^& _ >%tmp%\today.vbs
echo Right(100+Month(D),2) ^& "-" ^& Right(100+Day(D),2) >>%tmp%\today.vbs

for /f "tokens=1" %%a in (
'cscript.exe //Nologo %tmp%\today.vbs') do set today=%%a

del %tmp%\today.vbs
c:\winrar\winrar.exe a -r "c:\afterCompress-%today%.rar" "c:\toBeCompressedFolder"

--------------------8<----------------------


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top