Solved

Add date and time to zip backup file in Windows 7

Posted on 2013-11-05
1
511 Views
Last Modified: 2013-11-05
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
Comment
Question by:penguins_rule
1 Comment
 
LVL 28

Accepted Solution

by:
omgang earned 500 total points
ID: 39625421
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

OfficeMate Freezes on login or does not load after login credentials are input.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

20 Experts available now in Live!

Get 1:1 Help Now