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

	<<12/20/01; 1:28:37 AM by JES
		<<Use file.writeTextFile to write the files to disk, instead of file.writeWholeFile. This also removes the necessity for a bunch of code used to calculate Mac type/creator codes and line-endings.
	<<12/13/01; 4:34:37 PM by JES
		<<On MacOS X, write text files with a type of '    ' and a creator of 'text'.
	<<11/30/01; 12:59:47 PM by JES
		<<Write the files with the line-ending native to the platform.
	<<10/17/01; 1:41:42 AM by JES
		<<Delete any obsolete files. A file is obsolete if it's not defined at[relativePath], where relativePath is a slash-delimited path starting in the www/system/ sub-folder.
	<<6/18/01; 9:13:42 AM by DW
		<<This runs every time we do an install. Make sure the contents of the system folder is in synch with the one in the object database.
local (adrtable =;
local (systemfolder = + + file.getpathchar ());

local (adr);
for adr in adrtable { //install any files that don't exist or have been changed
	local (objectname = string.replaceall (nameof (adr^), "/", file.getpathchar ()));
	local (f = systemfolder + objectname);
	file.surefilepath (f);
	<<local (macCreator, macType)
	<<if system.environment.isCarbon //on MacOS X, creator is TextEdit, type is '    '
		<<macCreator = 'text'
		<<macType = '    '
	<<else //for Classic, creator is SimpleText, type is 'TEXT'
		<<macCreator = 'ttxt'
		<<macType = 'TEXT'
	<<bundle //set the mac type and creator
		<<local (extension = string.lower (string.nthField (objectname, '.', string.countFields (objectname, '.'))))
		<<case extension
				<<macCreator =
				<<macType = 'OPML'
				<<macCreator = user.html.prefs.textFileCreator
	local (flinstall = true);
	if file.exists (f) {
		if timemodified (adr) == file.modified (f) {
			flinstall = false}};
	if flinstall {
		<<local (eol = "\r\n")
		<<if system.environment.isMac //set eol
			<<if system.environment.isCarbon // eol is \n
				<<eol = "\n"
			<<else // eol is \r
				<<eol = "\r"
		<<local (filetext = string (adr^))
		<<bundle //convert to native line-endings
			<<filetext = string.replaceAll (filetext, "\r\n", "\r")
			<<filetext = string.replaceAll (filetext, "\n", "\r")
			<<filetext = string.replaceAll (filetext, "\r", eol)
		<<file.writewholefile (f, filetext, macType, macCreator)
		file.writeTextFile (f, string (adr^));
		file.setmodified (f, timemodified (adr));
		file.setcreated (f, timecreated (adr))}};
	<<else //on the mac, make sure the type and creator code are correct
		<<if system.environment.isMac
			<<file.setType (f, macType)
			<<file.setCreator (f, macCreator)

local (f);
fileloop (f in systemfolder, infinity) { //delete any files that should be deleted
	if f beginsWith {
	if radio.webserver.getfilemimetype (f) beginswith "text" {
		local (objectname = string.delete (f, 1, sizeof (systemfolder)));
		objectname = string.replaceall (objectname, file.getpathchar (), "/");
		local (adrobject =[objectname]);
		if not defined (adrobject^) {
			try {file.delete (f)}}}} //in a try because the file may be busy or locked

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.