I'm quite new to .net so would appreciate your help. My project is nearing completion and I would like to save my work prior to making changes each day, should something go wrong.

Eventually I would like to end up with a series of archived projects so that I could revert back to the last one if need be.

How would I do this? Or is there some other method of keeping my uncompleted but working project "safe".

Recommended Answers

All 2 Replies

I have two different versions of a command line script that I wrote. The first is written in python and the second in vbscript. The usage is the same for both (pick your poison).

archive <folder>

where <folder> is the name of the folder that you want to archive. For example, if you have a VB project in a folder named "booklib", go to the folder containing your VB projects and type

archive booklib

The script (either one) will create a zip file named

YYYY-MM-DD HH-MM booklib.zip

where YYYY-MM-DD is the current date and HH-MM is the current time.

If you use the VBS version, I suggest you type the following at the command prompt (once)

cscript //h:cscript //nologo //s

This sets the default vbscript processor to the command line (cscript.exe) version and save it (//s) as the default.

#                                                                                           #
#  Name:                                                                                    #
#                                                                                           #
#    archive.py                                                                             #
#                                                                                           #
#  Description                                                                              #
#                                                                                           #
#    Archives the given folder (and everything below) into a zip file where the zip file    #
#    name is "yyyy-mm-dd hh-mm folder.zip"                                                  #
#                                                                                           #
#  Audit:                                                                                   #
#                                                                                           #
#    2010-07-29 - converted to Python 3.1                                                   #
#    2010-07-26 - converted from vbScript to Python                                         #
#                                                                                           #

import os
import sys
import datetime
import zipfile

def formatPrefix ():
	"""
	-
	formatPrefix()
	
	Using the current date and time, format a string as "YYYY-MM-DD HH-MM "
	-
	"""
	
	now = datetime.datetime.now()
	res = "%02d-%02d-%02d %02d-%02d " % (now.year,now.month,now.day,now.hour,now.minute)
	return res

if len(sys.argv) < 2:
	print("archive <folder>")
	print()
	print("    <folder> must exist within the current working directory")
	sys.exit(0)

folder = os.path.split(sys.argv[1])[1]

if not os.path.isdir(folder):
	print("'" + folder + "' is not a folder within the current working directory")
	sys.exit(1)

file = formatPrefix() + folder + ".zip"

print()
print("archiving folder:",folder)
print("              as:",file)
print()

f = zipfile.ZipFile(file,'w',zipfile.ZIP_DEFLATED)

for dirpath, dirnames, filenames in os.walk(folder):
	for filename in filenames:
		print("          adding:",os.path.join(dirpath,filename))
		f.write(os.path.join(dirpath,filename))
	
f.close()
'                                                                                            '
'  Name:                                                                                     '
'                                                                                            '
'    Archive.vbs                                                                             '
'                                                                                            '
'  Description:                                                                              '
'                                                                                            '
'    This script will (recursively) archive the given directory. The zip file will be named  '
'    as YYYY-MM-DD HH;MM dirname.zip.                                                        '
'                                                                                            '
'  Usage:                                                                                    '
'                                                                                            '
'    archive dirname [exclude]                                                               '
'                                                                                            '
'    dirname:      the name of the directory to archive                                      '
'    exclude:      file name (or pattern) to exclude                                         '
'                                                                                            '
'  Example:                                                                                  '
'                                                                                            '
'    Let's say you are going to make code changes to one or more modules in the weather      '
'    application in f:\apps\weather. You want to archive the existing code in case it blows  '
'    up after the changes are made. You want to be able to restore the application files,    '
'    but you don't want to back up or restore the log files. Locate to the f:\apps           '
'    directory and type                                                                      '
'                                                                                            '
'    archive weather *.log                                                                   '
'                                                                                            '
'    All files in weather and below) will be archive except for files of the form *.log.     '
'                                                                                            '
'  Audit:                                                                                    '
'                                                                                            '
'    2006-01-12  jdeg  changes to allof use from coontext menu                               '
'    2001-07-30  jdeg  added exclude option                                                  '
'                                                                                            '

set wso = CreateObject("Wscript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")

set arg = Wscript.Arguments

if arg.Count >= 1 then

   if arg.Count >1 then
      exclude = " -x " & arg(1) & " "
   else
      exclude = ""
   end if

   currdate = Now()

   path = fso.GetParentFolderName(arg(0))
   fold = fso.GetFileName(arg(0))

   archive = path & Year(currdate) _
           & "-" & Right("0" & Month(currdate),2) _
           & "-" & Right("0" & Day(currdate),2) _
           & " " & Right("0" & Hour(currdate),2) _
           & ";" & Right("0" & Minute(currdate),2) _
           & " " & fold & ".zip"

   wso.run "zip -r " & """" & archive & """" & " " & """" & arg(0) & """" & exclude

end if

set arg = Nothing
set wso = Nothing

'msgbox "done"

I'm quite new to .net so would appreciate your help. My project is nearing completion and I would like to save my work prior to making changes each day, should something go wrong.

Eventually I would like to end up with a series of archived projects so that I could revert back to the last one if need be.

How would I do this? Or is there some other method of keeping my uncompleted but working project "safe".

Thanks, I'll give it a try. Very kind of you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.