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

system.verbs.builtins.file.filteredCopy

on filteredCopy (sourcepath, destpath, filter) {
	<<3.0.2: kernel now supports copying of folders themselves, retaining attributes or original
	local (pathchar = file.getPathChar ()); <<DW 11/3/97
	on kernelcall (sourcepath, destpath) {
		kernel (file.copy)};
	on copyonefile (sourcepath, destpath) {
		if not filter^ (sourcepath) { <<the filter says don't copy this file
			return (true)};
		sys.systemTask (); <<be extra sensitive to user input, other application tasks
		return (kernelcall (sourcepath, destpath))};
	
	if file.isFolder (sourcepath) { <<copying a folder
		local (topdest = destpath); <<a global to the whole copying process
		on foldercopy (folderpath, partialpath) {
			local (f, newfolder);
			if not filter^ (folderpath) { <<the filter says don't copy this folder
				return (true)};
			newfolder = topdest + partialpath;
			bundle { <<do folder checking
				if file.exists (newfolder) {
					if not file.isFolder (newfolder) {
						scriptError ("Can't copy because " + newfolder + " is a file, not a folder.");
						return (false)}}
				else { <<new folder doesn't exist, try to create it
					if not kernelcall (folderpath, newfolder) {
						return (false)};
					newfolder = filespec (newfolder)}}; <<in case caller omitted trailing pathchar
			fileloop (f in folderpath) {
				rollBeachBall ();
				if file.isFolder (f) {
					if not foldercopy (f, partialpath + file.fileFromPath (f)) { <<recurse
						return (false)}}
				else {
					if not copyonefile (f, newfolder + file.fileFromPath (f)) {
						return (false)}}}};
		return (foldercopy (sourcepath, ""))}
	else { <<just copying a file
		if string.hasSuffix (pathchar, destpath) {
			if not file.isFolder (destpath) {
				scriptError ("Can't copy the file into \"" + destpath + "\" because it is not a folder.")};
			destpath = destpath + file.fileFromPath (sourcepath)}
		else {
			if file.exists (destpath) and file.isFolder (destpath) {
				scriptError ("Can't copy the file as \"" + destpath + "\" because there is a folder at that location.")}};
		return (copyonefile (sourcepath, destpath))}}



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.