Solved

datetime stamp

Posted on 2004-10-19
2
707 Views
Last Modified: 2008-02-26
Utilizing wzzip, how would I write a script that plugs a system datetime stamp on the zip file name?

For example,

"c:\Program Files\WinZip\WZZIP.EXE" c:\docs<datetime stamp>.zip c:\*.doc

would produce:

c:\docs10-19-2004 03:00.zip
0
Comment
Question by:arichexe
2 Comments
 
LVL 7

Expert Comment

by:msice
ID: 12352928
For this you will need a .vbs WSH script like so it will create the zip file for you.

'VBScript

DIM fso, NewsFile, oFS
  var = cSTR(now())
  var = replace(var, "/" , "-" )
  var = replace(var, ":" , "_" )
  var = replace(var, "  " , "~" )
Set fso = CreateObject("Scripting.FileSystemObject")
Set NewsFile = fso.CreateTextFile("c:\docs"&var&".zip", True)
NewsFile.Close
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 250 total points
ID: 12353644
No need to use VBscript - you can do the same in effectively one line of a batch script:

for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do for /f "tokens=1,2,3 delims=: " %%m in ('time /t') do set filename=MyFileName%%a-%%b-%%c %%m%%n%%o

Note:
%%a = Month
%%b = Day
%%c = Year
%%m = Hour
%%n = Minute
%%o = AM or PM

Note, you can't use a colon (:) in a filename.

The above script effectively sets the variable filename (%filename%) to a name using the date and time code you request (although not in 24 hour format).  

To use in conjuction with your script that zips things, you'd do this:

----------------------------
for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do for /f "tokens=1,2,3 delims=: " %%m in ('time /t') do set filename=MyFileName%%a-%%b-%%c %%m%%n%%o
"c:\Program Files\WinZip\WZZIP.EXE" c:\%filename%.zip c:\*.doc
----------------------------
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now