Solved

datetime stamp

Posted on 2004-10-19
2
708 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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…
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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