Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: url or file ?

From: ingo::2b1::de at: 4-Oct-2003 21:18

Hi Patrick, how are you? patrick wrote:
> Hi List, > > I already know how to test url and file. > >>>url? > > == true > >>>file? %index.html > > == true > > But what if these came as strings > >>>test: ["" "index.html"]
The problem here (apart from the 'load problems already discussed), is that rebol won't understand a file that is written in non Rebol format (that is, without the leading % sign). A function that will do the trick, as long as you are certain there will only be urls and files in your data, is this: string-to-url-or-file: func [s [string!] /local uf][ either url? uf: attempt[load s ] [uf][to file! s]] ] When your data is a url, load should always succeed, so attempt returns either a url, or somthing else, or none (e.g., if load failed) in the latter cases we just convert it to a file.
>> test: ["" "index.html"]
== ["" "index.html"]
>> repeat d test [ print [ f d " " type? f d ]] url index.html file Kind regards, Ingo