Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automating the ZIP
Message
From
09/10/2001 12:55:26
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
00566018
Message ID:
00566049
Views:
26
>Hello All,
>I need to automate the "zipping process". I have winZip 8.0. How do I go about doing this??
>
>Thanks
>
>Sandy

I am including my own solution for automating backup. It's primitive, but works fine for me.

Since I use pacomp, you have to adjust the command-line parameters for WinZip.

HTH, Hilmar.


It should not be necessary to change the generic backup program, backup.prg. Parameters are read from a text-file, backupoptions.txt. I am including both.



The generic backup program:
* Generic backup program

* Missing:
*   More error checking (paths don't exist, etc.)
*   comments at end-of-line in function LoadVariables

* Load options (variables) from text file
LoadVariables("backupoptions.txt", "public")

define window output from 0,0 to srows() - 1, scols() -1 font "Courier"
activate window output

* Copy to temp dir
clear
? "Copying to temp folder"
DosCommand("xcopy " + lcFromFolder + " " + lcTempFolder + "\ /s")

* Delete excluded files (from temp dir)
local lcDeleteSkeleton
lcExcludeFiles = strtran(lcExcludeFiles, ",", chr(13) + chr(10))
for i = 1 to memlines(lcExcludeFiles)
	lcDeleteSkeleton = alltrim(mline(lcExcludeFiles, i))
	? "Deleting " + lcDeleteSkeleton + " from temp folder"
	DeleteWithSub(lcTempFolder + "\" + lcDeleteSkeleton)
next

* Backup
? "Starting compression"
lcBackupCommand = strtran(lcBackupCommand, "%1", lcTempFolder)
lcArchiveFileName = lcBaseName + str(year(datetime()),4)
if lnDetailLevel >= 2
	lcArchiveFileName = lcArchiveFileName + "-" + padl(month(datetime()), 2, "0")
endif
if lnDetailLevel >= 3
	lcArchiveFileName = lcArchiveFileName + "-" + padl(day(datetime()), 2, "0")
endif
if lnDetailLevel >= 4
	lcArchiveFileName = lcArchiveFileName + "-" + padl(hour(datetime()), 2, "0")
endif
if lnDetailLevel >= 5
	lcArchiveFileName = lcArchiveFileName + "-" + padl(minute(datetime()), 2, "0")
endif
if lnDetailLevel >= 6
	lcArchiveFileName = lcArchiveFileName + "-" + padl(sec(datetime()), 2, "0")
endif
lcArchiveFileName = lcArchiveFileName + "." + lcExtension
DosCommand(strtran(lcBackupCommand, "%2", lcDestination + "\" + lcArchiveFileName))

* Erase temp files
? "Erasing temp files"
DosCommand("deltree /y " + lcTempFolder)

* Copy to additional destination
if not empty(lcDestination2)
	? "Copying to additional folder"
	copy file (lcDestination + "\" + lcArchiveFileName) to (lcDestination2 + "\" + lcArchiveFileName)
endif

? "Backup completed"
wait window "Backup completed." + chr(13) + "This message will close in 20 seconds.";
	timeout 20

FUNCTION DeleteWithSub(tcFullPath)
	local lcDir, lcSkeleton
	lcDir = justpath(tcFullPath)
	lcSkeleton = justfname(tcFullPath)
	DelFilesSub(lcDir, lcSkeleton)
ENDFUNC

FUNCTION DelFilesSub(tcDir, tcSkeleton)
	local laFileList(1,1), i, lcDir
	for i = 1 to adir(laFileList, tcDir + "\" + tcSkeleton)
		erase (tcDir + "\" + laFileList(i, 1))
	next
	for i = 1 to adir(laFileList, tcDir + "\*.*", "D")
		if laFileList(i, 1) # "."
			lcDir = tcDir + "\" + laFileList(i, 1)
			DelFilesSub(lcDir, tcSkeleton)
		endif
	next
ENDFUNC

FUNCTION LoadVariables(tcFileName, tcDeclarationType)
	* Loads variables from a text file
	local lcOptions, i, lcLine, lnMemoWidth, lcVariable, lcDeclaration
	lnMemoWidth = set("memowidth")
	set memowidth to 8192
	lcOptions = FileToStr(tcFileName)
	* The use of _mline is much faster than providing a line number to mline().
	* See sample in VFP help file.
	_mline = 0
	for i = 1 to memlines(lcOptions)
		lcLine = mline(lcOptions, 1, _mline)
		if not empty(lcLine) and not inlist(left(lcLine, 1), ";", "[")
			* Declare variable public. Private and local don't make sense right now,
			* since these would be erased on function exit. The function would have
			* to be changed to an #include file this feature.
			if not empty(tcDeclarationType)
				lcVariable = alltrim(left(lcLine, at("=", lcLine) - 1))
				if not ("(" $ lcVariable or "[" $ lcVariable) && don't declare arrays
					lcDeclaration = tcDeclarationType + space(1) + lcVariable
					&lcDeclaration
				endif
			endif
			* Assign variable
			&lcLine
		endif
	next
	set memowidth to lnMemoWidth
ENDFUNC

FUNCTION DosCommand(lcCommand)
	activate window output
	? "DOS command: " + lcCommand
	lcCommand = "run " + lcCommand
	activate screen
	&lcCommand
	activate window output
ENDFUNC
A sample option file:
[COMMENTS]
; Options for automated backup
; Use semicolon and square brackets, at position 1, for comments.
; Don't delete any variables from this file!
; Most variables need values, lcDestination2 can hold the empty string: ""
; Missing: samples for major compression programs.
; The sample is for pacomp.exe, the command-line version of
; PowerArchiver (www.powerarchiver.com; freeware up to version 6.1; version 7 is shareware)

[OPTIONS START HERE]

[FOLDERS]
; Location of files to backup
lcFromFolder = "c:\projects"

; Copy files to this location
lcTempFolder = "c:\TempCopy"

; Main destination
lcDestination = "c:\Internal_Backups"

; Destination for additional copy
lcDestination2 = "\\MyServer\Backups"


[OTHER OPTI0NS]
lcExcludeFiles = "*.fxp,*.exe,*.bak,*.tbk,*.tmp,*.chm,*.idx,*.old,Project1\data\*.*"

; Filename of compressed archive
lcBaseName = "Project-"
lcExtension = "CAB"

; Backup command
; %1 is a placeholder for origin folder (i.e., temp folder); filename (*.*) not included
; %2 is a placeholder for destination folder;
;   filename (e.g. mydata-2001-04-21.cab) is provided in program.
lcBackupCommand = "c:\progra~1\pautil\pacomp.exe -a -p %2 %1\*.*"

; Detail level for filename: 3 = yyyy-mm-dd; 4 adds hours, 5 adds minutes, 6 adds seconds
lnDetailLevel = 5

[END OF FILE]
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform