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

system.verbs.builtins.radio.upstream.saveDirectoryXml

on saveDirectoryXml (folder) {
	<<Changes
		<<12/20/01; 1:22:34 AM by JES
			<<Use file.writeTextFile to write the file, instead of file.writeWholeFile.
		<<6/23/01; 8:30:39 PM by DW
			<<Complete rewrite. Went from 1.6 seconds to 0.2 seconds. Not too bad!
			<<bundle //old version, builds an outline
				<<local (directoryOutline)
				<<new (outlinetype, @directoryOutline)
				<<local (oldtarget = target.set (@directoryOutline))
				<<on dofolder (folder, fltoplevel=false) //return true if at least one file was inserted
					<<local (f, insertdir = right, fname, atts, flfolder, adrfile, flinserted)
					<<fileloop (f in folder)
						<<fname = file.filefrompath (f)
						<<if fname endswith file.getpathchar ()
							<<fname = string.mid (fname, 1, sizeof (fname) - 1)
						<<if fltoplevel //don't include the directory in the directory
							<<if radio.data.upstream.directoryFileNames contains fname
								<<continue
						<<flfolder = file.isfolder (f)
						<<if not flfolder
							<<radio.file.getFileAttributes (f, @adrfile)
							<<if adrfile^.upstream.ctuploads == 0
								<<continue
						<<op.insert (fname, insertdir)
						<<flinserted = true
						<<new (tabletype, @atts)
						<<if flfolder
							<<atts.type = "folder"
							<<if dofolder (f)
								<<op.go (left, 1)
							<<else
								<<op.deleteline ()
								<<flinserted = false
						<<else
							<<radio.file.getFileAttributes (f, @adrfile)
							<<atts.type = "file"
							<<atts.url = adrfile^.upstream.url
							<<atts.size = file.size (f)
							<<atts.whenLastUploaded = adrfile^.upstream.whenLastUploaded
							<<atts.whenCreated = file.created (f)
						<<if flinserted
							<<op.attributes.addgroup (@atts)
							<<insertdir = down
					<<return (insertdir == down)
				<<dofolder (folder, fltoplevel:true)
				<<op.firstsummit (); op.promote (); op.deleteline ()
				<<window.zoom (@directoryOutline)
				<<target.set (oldtarget)
				<<scratchpad.directoryoutline = directoryoutline; edit (@scratchpad.directoryoutline)
				<<local (xmltext = op.outlinetoxml (@directoryOutline))
				<<local (f = folder + radio.data.upstream.directoryFileName) 
				<<file.writewholefile (f, xmltext, 'OPML', frontier.id)
				<<return (f)
	on callback (f) { //skip folders with their own #upstream.xml files
		if file.isfolder (f) {
			return (not file.exists (f + radio.data.fileNames.upstreamFileName))};
		if file.filefrompath (f) beginswith "#" {
			return (false)};
		return (true)}; //include it
	local (f = folder + radio.data.upstream.directoryFileName);
	local (xmltext = radio.file.folderToOpml (folder, @callback));
	file.writeTextFile (f, xmltext);
	return (true)}
<<bundle //test code
	<<local (tc = clock.ticks ())
	<<for i = 1 to 1
		<<saveDirectoryXml ("Backup:Radio UserLand:www:system:upstream:")
	<<dialog.alert (double (clock.ticks () - tc) / 60)



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.