回答
总之,一个文件URL的格式如下:
file://localhost/absolute/path/to/file [ok]
,或者你可以省略host(但不是斜线):
file:///absolute/path/to/file [ok]
但不是这样的:
file://file_at_current_dir [no way]
也没有:
file://./file_at_current_dir [no way]
我只是确认,通过Python的urllib2.urlopen()
从 http://en.wikipedia.org/wiki/File_URI_scheme更多细节:
"file:///foo.txt" is okay, while "file://foo.txt" is not,
although some interpreters manage to handle the latter
是否也可以使用file:/ absolute/path或file:relative(即使这不起作用),因为您可以删除文件协议的权限。 –
这是不可能使用完整的文件: '' 与URI或'..'分段在没有该路径的根部分的路径中。无论你使用'file://./.bashrc'还是'file:///./.bashrc',这些路径都没有意义。如果你想用一个相对链接,使用它没有协议/授权部分:
<a href="./.bashrc">link</a>
如果您想使用完整的URI,你必须告诉根相对于它的相对路径是:
<a href="file:///home/kindrik/./.bashrc">link</a>
The path segments "." and "..", also known as dot-segments, are
defined for relative reference within the path name hierarchy. They
are intended for use at the beginning of a relative-path reference
(Section 4.2) to indicate relative position within the hierarchical
tree of names. This is similar to their role within some operating
systems' file directory structures to indicate the current directory
and parent directory, respectively. However, unlike in a file
system, these dot-segments are only interpreted within the URI path
hierarchy and are removed as part of the resolution process (Section
5.2).
The complete path segments "." and ".." are intended only for use
within relative references (Section 4.1) and are removed as part of
the reference resolution process (Section 5.2). However, some
deployed implementations incorrectly assume that reference resolution
is not necessary when the reference is already a URI and thus fail to
remove dot-segments when they occur in non-relative paths. URI
normalizers should remove dot-segments by applying the
remove_dot_segments algorithm to the path, as described in Section 5.2.4.
The complete path segments "." and ".." are intended only for use
within relative references (Section 4.1) and are removed as part of
the reference resolution process (Section 5.2)
RFC 3986描述甚至消除这些的算法 “”和来自URI的“..”。
在终端中,您可以使用“$ PWD”键入“file://$PWD/.bashrc”来引用当前目录。
我在我的代码中进行替换 – wener
这对于相对路径以及“file://$PWD/../parentchilddir/somefile.txt” – nilsmagnus
- 1. URI方案不是“文件”
- 2. 将Url和相关文件路径加入有效的Uri?
- 3. URI方案不是“文件”插件错误
- 4. PyCharm文件方案
- 5. 签出与加载解决方案相关的文件
- 6. URI方案不是“文件”。无法从类路径读取文件
- 7. 关于生成的文件名和文件上传相关
- 8. 未知URI方案,同时打开bin文件
- 9. 在文件URI方案中使用Windows环境变量
- 10. 提供的URI方案“文件”无效期望'http'
- 11. 如何通过bash中的FILE URI方案下载文件?
- 12. 与NuGet和project.json一起使用解决方案相关包文件夹
- 13. Access文件URI
- 14. PHPMailer,AddStringAttachment和Data URI方案
- 15. 重写URI与htaccess的相关PHP文件
- 16. 获取Visual Studio解决方案文件和文件夹
- 17. 时间事件的URI方案
- 18. msbuild解决方案文件
- 19. Android文件:方案Cookie
- 20. 从uri获取文件名和路径作为文本文件
- 21. 位置和相关映像文件
- 22. 创建SVG文件和相关命令
- 23. 读取文件和相关信息
- 24. 目录和文件相关的疑惑?
- 25. * .dsc文件如何与* .deb和源代码文件相关
- 26. 异步加载js文件和其他相关的js文件
- 27. JavaFX Jar文件相关性和控制下载文件大小
- 28. html块的相关js文件和css文件
- 29. 命名约定形式相关的文件和文件夹
- 30. 头文件(.h),库文件(.lib)和DLL(.dll)文件如何相关
根据维基百科http://en.wikipedia.org/wiki/Uniform_resource_identifier显然你可以忽略这个方案,并且当你指的是相对的时候就有“./.bashrc”作为uri。但是,这只是一个猜测,我不确定它究竟是如何工作的。 – Tony
@Tony - 谢谢,在.docx文件中做相对引用时工作正常 - 只需解压,找到“file:/// long-absolute-path/relative-path”引用,并替换为“relative-path” – tucuxi
严格省略前缀并不总是有效,因为URI可以使用百分号(例如'%20' = space)编码的特殊字符;取决于应用程序,您可能需要用其实际表示来替换转义字符。 – sleblanc