Monday, November 08, 2010 at 12:02 AM.
system.verbs.builtins.file.urlToFile
on urlToFile (s) {
local (prefix = "file:///");
if not (string.lower (s) beginsWith prefix) {
scriptError ("Can't convert \"" + s + "\" to a filespec because it doesn't begin with \"" + prefix + "\".")};
s = string.delete (s, 1, sizeOf (prefix));
s= string.urlDecode (s);
case sys.os () {
"MacOS" {
s = string.replaceAll (s, "/", ":")};
"Win95";
"WinNT" {
<<11/13/97 at 2:40:52 AM by DW
<<I tested file URLs in MSIE 4.0, we produce a URL that's compatible
local (ix = string.patternMatch ("/", s)); <<find the first slash
if ix > 1 { <<found one, and it's not the first char
if s [ix - 1] != ":" { <<the previous char is not a colon
s = string.insert (":", s, ix)}};
<<s = string.replace (s, "/", ":/") <<add a colon after the drive letter (or name)
s = string.replaceAll (s, "/", "\\")}};
return (s)};
<<bundle <<test code
<<dialog.alert (urltofile (file.filetourl (frontier.getprogrampath ())))
<<dialog.alert (urltofile ("file:///Macintosh%20HD/Online%20Docs/admin/credits.html"))
<<urltofile ("oh the buzzing")
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.