W3C home > Mailing lists > Public > uri@w3.org > May 2005

Re: Converting filenames to file: URIs

From: Al Gilman <Alfred.S.Gilman@IEEE.org>
Date: Thu, 12 May 2005 10:19:55 -0400
Message-Id: <p06110400bea9151295a0@[10.0.1.2]>
To: <uri@w3.org>

At 1:40 PM +0100 5/12/05, Graham Klyne wrote:
>
>What's missing here?  How does this stand up on a Mac platform?

There is a laundry list Mike Brown contributed last year,
in response to a similar question from you.

http://lists.w3.org/Archives/Public/uri/2004Jul/0013

[notably the UNC addressing of networked storage.]

More at

http://www.w3.org/Search/Mail/Public/search?type-index=uri&index-type=t&keywords=network+File+Windows&search=Search

Al

>I've recently been tinkering with a Java program that uses URIs, 
>finding that it doesn't work on Windows because of its filename->URI 
>conversion logic.  This has prompted me to map out a generic 
>function to map a filename to a file: URI.
>
>Examples:
>Unix:
>   Filename /foo/bar maps to file:///foo/bar
>   i.e. prepend "file://"
>Windows:
>   Filename C:\foo\bar maps to file:///C:foo/bar
>   i.e. prepend "file:///" and map \ to /.
>
>This has prompted me to try and create a generic, operating-system 
>independent function to turn (almost all) filename strings into 
>corresponding file: URI string.  My first attempt is this, which 
>attempts to cover Windows and Unix:
>
>[[
>     public static String uriFromFilename(
>         String filename)
>         {
>         StringBuffer mapfilename = new StringBuffer( filename ) ;
>         for ( int i = 0 ; i < mapfilename.length() ; i++ )
>             {
>             if ( mapfilename.charAt(i) == '\\' )
>                 mapfilename.setCharAt(i, '/') ;
>             }
>         if (filename.charAt(0) == '/')
>             {
>             return "file://"+mapfilename.toString() ;
>             }
>         else
>             {
>             return "file:///"+mapfilename.toString() ;
>             }
>         }
>]]
>
>What's missing here?  How does this stand up on a Mac platform?
>
>#g
>
>
>------------
>Graham Klyne
>For email:
>http://www.ninebynine.org/#Contact
Received on Thursday, 12 May 2005 15:07:38 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:25:09 UTC