Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

Add date and time to zip backup file in Windows 7

In Windows 7, I need a script to zip a directory into a file which will have the current date and time on the file name.

example:
folder to backup is c:\zipin\eDOC

creates backup1311041211.zip
        where 131104 is Nov 04, 2013
        where 1211 is 12:11 pm
0
penguins_rule
Asked:
penguins_rule
1 Solution
 
omgangCommented:
This should do it.
OM Gang


Option Explicit


Dim oFSO, oShell, oFld, zipFil
Dim strDir, strZip, strDay, strTime, strDate
Dim dteDateTime

dteDateTime = Now()

If Len(DatePart("d", dteDateTime) = 1) Then
      strDay = "0" & DatePart("d", dteDateTime)
Else
      strDay = DatePart("d", dteDateTime)
End If

strDate = Right(DatePart("yyyy", dteDateTime), 2) & DatePart("m", dteDateTime) & strDay & DatePart("h", dteDateTime) & DatePart("n", dteDateTime)

strDir = "c:\ziping\eDOC\"
strZip = "C:\temp\backup" & strDate & ".zip"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Shell.Application")
'Set oFile = oFSO.GetFile(strFile)
Set oFld = oFSO.GetFolder(strDir)
 

Set zipFil = oFSO.CreateTextFile(strZip)
zipFil.WriteLine Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
zipFil.Close

oShell.NameSpace(strZip).CopyHere oFld.Path
wscript.sleep 500

Set zipFil = Nothing
Set oShell = Nothing
Set oFld = Nothing
set oFso=Nothing
wscript.quit
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now