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

on getCatName (f, adrCatName, adrblog=radio.weblog.init ()) {
		<<1/5/02; 5:12:30 PM by JES
			<<Given the path to a weblog source file on disk, get the category name, and save it in the variable specified by adrCatName. Returns true if the file is in a category, or false if not.
			<<If the script returns true, then the value of adrCatName^ corresponds to the name of a table in adrBlog^.categories.
				<<f -- the path to a file on disk
				<<adrCatName -- the address of a variable in which to store the category name.
				<<adrBlog -- the address of the weblog -- defaults to the address returned by radio.weblog.init.
	local (pc = file.getPathChar ());
	local (adrcat, adrcats = @adrblog^.categories);
	for adrcat in adrcats {
		local (catname = nameOf (adrcat^));
		local (catfolder = radio.weblog.file.getCategoryFolder (catname, adrblog));
		if string.lower (f) beginsWith string.lower (catfolder) { //found it
			adrCatName^ = catname;
			return (true)}};
	return (false)}
<<bundle //test code
	<<local (catname, pc = file.getPathChar ())
	<<local (f = radio.weblog.file.getCategoryFolder ("default") + "2002" + pc + "01" + pc + "04.txt")
	<<getCatName (f, @catname)
	<<dialog.notify (catname)

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.