20

I use file:// to point to local file.

file://localhost/Users/smcho/Desktop/softwaredevelop/15.pdf

Can't I use file:// to point to the local file relative to current directory? I mean the current directory by where the file containing the file:// is located.

file://./../15.pdf

I need file:// to link a file in Leo. With Leo, I use file:// to link to a local file, and I want to point to files that are located in relative directory to current directory. I asked similar question in Google forum.

5 Answers 5

22
file://

is for absolute paths. But the following will be relative to your working directory:

file:./15.pdf
1
  • alas, this does not work in OpenOffice: "The operation on ../15.pdf was started with an invalid parameter"
    – Michael
    Aug 10, 2015 at 18:08
7

I'm not familiar with the Leo outlining software, but if it handles links the same way a web browser does, try the following

../15.pdf
file:../15.pdf

Notes

  • A relative link usually doesn't include the protocol (like http: or https: or file:). When the protocol is omitted, a web browser will use the same protocol as the page the link appears in.

  • An absolute link begins with //. A relative link shouldn't begin with //.

  • The ./ is only needed if you are linking to the folder that contains the page exactly. Otherwise, you can leave it out and start with ../.

    ---- In your thread in the leo-editor group you said file:./../15.pdf caused an error. Maybe the ./../ combination is confusing your software. Perhaps file:../15.pdf will work?

1
  • Thanks for the answer, but both approaches don't seem to work with Leo.
    – prosseek
    Nov 13, 2010 at 18:23
2

Relative to what? URIs by definition are absolute. However you can make your URI relative to a known location, like this:

file://localhost/Users/smcho/Desktop/softwaredevelop/somedir/../15.pdf

Update From what you said it sounds like you are trying to open a PDF from within your application. Typically this is done by just executing the file and letting the OS figure out how to handle it. In Python you would use something like:

os.startfile("../15.pdf")

URIs like file://... are typically used in the context of web-based applications.

4
  • 1
    Thanks for the answer. I need to point to a file relative to the current directory (where the file is located). Can file:// do that?
    – prosseek
    Nov 12, 2010 at 21:08
  • 1
    The current directory in what context? What application are you using? Is this on some kind of local web page or something?
    – heavyd
    Nov 12, 2010 at 21:16
  • 1
    if you are referencing programmatically file:// is NOT the way to do it. Nov 12, 2010 at 21:26
  • I elaborated the question. The current directory means the directory where Leo file is located.
    – prosseek
    Nov 12, 2010 at 21:47
0

According to RFC 8089: The "file" URI Scheme:

The path component represents the absolute path to the file in the file system. See Appendix D for some discussion of system-specific concerns including absolute file paths and file system roots.

So there is no syntax for relative file system paths in the file uri scheme.

Also file:./some-file.txt is invalid syntax according to RFC 8089, as the URI path always has to be a path-absolute rule which is given in RFC3986: Uniform Resource Identifier (URI): Generic Syntax as

path-absolute = "/" [ segment-nz *( "/" segment ) ]
-2

MyClass.class.getResource("/com/fnf/si/DepAcctInq_V02.wsdl"); It worked for me

1
  • 1
    Welcome to superuser: While this may or may not answer the question it would be a better answer if you could provide some explanation why your solution works with detail and an easy to follow instructions. If you feel your answer is correct do these things and re-edit. Please take a couple of minutes and read:- superuser.com/help .Answering: superuser.com/help/how-to-answer, again welcome to superuser.Thankyou
    – mic84
    Feb 2, 2018 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.