2011-10-22 26 views
42

मान लीजिए कि उरी के लिए योजना "फ़ाइल" है। यह भी मान लें कि पथ '।' से शुरू होता है।फाइल उरी योजना और सापेक्ष फ़ाइलें

एक उदाहरण पथ './bashrc' है। फुलुरी कैसे दिखेंगे? 'फ़ाइल: //./.bashrc' मेरे लिए अजीब प्रतीत होता है।

+2

विकिपीडिया के मुताबिक http://en.wikipedia.org/wiki/Uniform_resource_identifier जाहिर है कि आप केवल योजना को छोड़ सकते हैं और जब आप तुलनात्मक रूप से संदर्भ दे रहे हैं तो उरी के रूप में "./bashrc" है। हालांकि, यह सिर्फ एक अनुमान है और मुझे यकीन नहीं है कि यह वास्तव में कैसे काम करता है। – Tony

+2

@ टोनी - धन्यवाद, यह .docx फ़ाइलों में सापेक्ष संदर्भ बनाने के लिए ठीक काम करता है - बस अनजिप करें, "फ़ाइल: /// लंबे-पूर्ण-पथ/सापेक्ष-पथ" संदर्भ ढूंढें, और "सापेक्ष-पथ" – tucuxi

+0

के साथ प्रतिस्थापित करें उपसर्ग को सख्ती से छोड़ना हमेशा काम नहीं करता है, क्योंकि यूआरआई में प्रतिशत संकेतों के साथ एन्कोड किए गए विशेष वर्ण हो सकते हैं (उदाहरण के लिए '% 20' = space); एप्लिकेशन के आधार पर आपको बच निकले वर्णों को उनके वास्तविक प्रतिनिधित्व के साथ बदलने की आवश्यकता होगी। – sleblanc

उत्तर

45

संक्षेप में, एक फ़ाइल URL का रूप ले लेता है:

file://localhost/absolute/path/to/file [ok] 

या आप मेजबान (लेकिन स्लैश) छोड़ सकते हैं:

file:///absolute/path/to/file [ok] 

लेकिन इस:

file://file_at_current_dir [no way] 

और न ही यह:

file://./file_at_current_dir [no way] 

मैं सिर्फ पुष्टि की है कि अजगर के 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 
+0

क्या फ़ाइल का उपयोग करना भी संभव नहीं है:/पूर्ण/पथ या फ़ाइल: सापेक्ष (भले ही यह काम नहीं करेगा) क्योंकि आप फ़ाइल प्रोटोकॉल के लिए प्राधिकरण को हटा सकते हैं। –

15

यह पूरी फ़ाइल का उपयोग करना असंभव है: '।' साथ यूआरआई या '..' उस पथ के रूट भाग के बिना पथ में सेगमेंट। चाहे आप 'file: //./.bashrc' या 'file: ///./.bashrc' का उपयोग करें, इन पथों का कोई अर्थ नहीं होगा। आप एक रिश्तेदार लिंक का उपयोग करना चाहते हैं, तो यह प्रोटोकॉल/अधिकार हिस्सा बिना उपयोग करें:

<a href="file:///home/kindrik/./.bashrc">link</a> 
:

<a href="./.bashrc">link</a> 

आप पूर्ण यूआरआई का उपयोग करना चाहते हैं, तो आप एक रूट रिश्तेदार जो करने के लिए अपने रिश्तेदार पथ है बताना होगा

करने के लिए RFC 3986

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 के अनुसार इन को हटाने की भी एक एल्गोरिथ्म का वर्णन करता है "।" और यूआरआई से ".."।

12

टर्मिनल में आप वर्तमान निर्देशिका को संदर्भित करने के लिए "$ PWD" का उपयोग करके "फ़ाइल: //$PWD/.bashrc" टाइप कर सकते हैं।

+0

मैं अपने कोड – wener

+0

में प्रतिस्थापन करता हूं यह सापेक्ष पथों के लिए भी ठीक काम करता है, "फ़ाइल: //$PWD/../parentchilddir/somefile.txt" – nilsmagnus

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^