Monday, November 08, 2010 at 12:01 AM.

system.verbs.apps.FinderMenu.commands.backup.doIt

FinderMenu.init ();
local (backupFolder = user.finderMenu.finderBackupFolder);
local (somethingDone = false);
local (count = 0);

<<on backupVisit (sourcePath)
	<<if file.isFolder (sourcePath) <<we only backup folders
		<<local (destPath = backupFolder + file.fileFromPath (sourcePath))
		<<file.sureFolder (destPath) <<make sure the folder exists
		<<
		<<local (lastbackup = FinderMenu.commands.backup.mostRecentBackup (destPath))
		<<local (backupname = "backup #" + (lastbackup + 1))
		<<local (newFolder = destPath + backupname + ":")
		<<file.newFolder (newFolder)
		<<
		<<fileloop (f in sourcePath) <<copy the files into the backup folder
			<<if FinderMenu.commands.backup.getBackupNumber (f) == 0 <<don't copy a backup folder
				<<local (fname = file.fileFromPath (f))
				<<msg (backupname + ":" + fname)
				<<file.copy (f, newFolder + fname)
				<<count++
		<<somethingDone = true
	<<return (true)

if (backupFolder == "") or (not file.exists (backupFolder)) {
	scriptError ("Use the Set Backup Path command to set your backup folder.")};
file.sureFolder (backupFolder); <<make sure it exists

local (sourcePath, flfolder, destPath, lastbackup, backupname, newFolder);
for sourcePath in FinderMenu.getSelectionList () {
	flfolder = file.isFolder (sourcePath);
	destPath = backupFolder + file.fileFromPath (sourcePath);
	if not flfolder {
		destPath = destPath + ":"};
	file.sureFolder (destPath); <<make sure the folder exists
	
	lastbackup = FinderMenu.commands.backup.mostRecentBackup (destPath);
	backupname = "backup #" + (lastbackup + 1);
	newFolder = destPath + backupname + ":";
	file.newFolder (newFolder);
	
	on dofile (f) {
		local (fname = file.fileFromPath (f));
		msg (backupname + ":" + fname);
		file.copy (f, newFolder + fname);
		count++};
	if flfolder {
		fileloop (f in sourcePath) { <<copy the files into the backup folder
			if FinderMenu.commands.backup.getBackupNumber (f) == 0 { <<don't copy a backup folder
				dofile (f)}}}
	else {
		dofile (sourcepath)};
	somethingDone = true;
	return (true)};

if somethingDone {
	msg ("Backup finished at " + clock.now () + ".")}
else {
	dialog.alert ("Select one or more folders before choosing this command.")};

Finder.bringToFront ();
return (true)



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.