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


on importFolder (folder) {
	<<Monday, February 23, 1998 at 10:58:34 AM by DW
		<<This script had never been updated for Frontier 5 or Windows. 
		<<It could only read from the resource fork. Oops.
		<<Removed the first parameter, the address of the table we're going to import into.
		<<This never worked, because it depended on the folder name being the same as the table name.
		<<This can't be true due to limits in the file systems.
		<<Instead, we use the address that's stored in each of the files.
	local (f, flgotfile, flmac = sys.os () beginsWith "Mac");
	fileloop (f in folder, infinity) {
		flgotfile = false;
		if flmac {
			try { //see if it's an old format, Frontier 4-compatible file
				local (adr);
				rez.getNthResource (f, 'data', 1, @adr, @resdata);
				msg (adr);
				unpack (@resdata, @resdata);
				unpack (@resdata, @resdata);
				table.moveAndRename (@resdata, adr);
				flgotfile = true}};
		if not flgotfile { //not Mac or not resource-based file
			<<ugly -- we have to crib code because fatPages.importFatFile doesn't do a table.surePath
			local (pageSource = string (file.readwholeFile (f)), atts);
			pageSource = string.replaceAll (pageSource, cr + lf, cr);
			pageSource = string.replaceAll (pageSource, lf, cr);
			if not fatPages.getPageAtts (@pageSource, @atts) {
				scriptError ("The file, \"" + f + "\", does not contain an embedded object.")};
			if not defined (atts.pageData) {
				scriptError ("The file, \"" + f + "\", does not contain an embedded object.")};
			local (x = atts.objectType, objectType);
			local (prefix = "application/x-frontier-");
			if not (x beginsWith prefix) {
				return (nil)};
			objectType = string.delete (x, 1, sizeof (prefix));
			local (data = binary (base64.decode (atts.pageData)));
			setBinaryType (@data, objectType);
			table.surePath (string (atts.adrPageData)); //here's the new bit that's not in fatPages.importFatFile
			unpack (@data, atts.adrPageData);
			msg (atts.adrPageData)}}};

<<bundle <<test code
	<<local (folder = "d:\\test\\")
	<<importfolder (folder)
	<< ()

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.