In “../A/D/E/img.jpg”, the leading “..” moves from the current directory B up one level to A, and then it tries to enter a directory named A. However, only B and D are directly under A; there is no A inside A. This is the mistake of overlooking that “..” already points to A, and writing the name A a second time.
○イ
正解The correct answer is イ, “../D/E/img.jpg”. First check the hierarchy in the figure: A is at the top, B and D sit directly under it, C is directly under B, and E is directly under D. The HTML document is placed in directory B, so the current directory (where you are now) is B. The route from here to img.jpg inside E is B → A → D → E. By specification method (3), the directory one level up is written as “..”, so the step from B up to its parent A becomes “..”. Next you enter D, which is directly under A, giving “/D”; then you enter E, which is directly under D, giving “/E”; finally you append the file name “/img.jpg”. Joining these gives “../D/E/img.jpg”, so イ is correct. The key points are that A, the directory you moved up to, is already expressed by “..” and so its name need not be written again in the path, and that D does not exist inside B, so the “..” that goes up one level cannot be omitted.
×Incorrectウ
In “./A/D/E/img.jpg”, by specification method (2) the leading “.” refers to the current directory, that is B, so it assumes that A is directly under B. However, only C is directly under B; A is the parent of B, not its child. To go to the parent you must use “..”, not “.”.
×Incorrectエ
In “./D/E/img.jpg” as well, the leading “.” refers to the current directory B, so it assumes that D is directly under B. In the figure, however, D is at the same level as B (both are children of A), that is, a sibling directory, so you cannot enter D directly from B. You can reach D only after first going up to the parent A with “..”.
ここがポイント
Basic symbols of a relative path: “.” means the current directory (where you are now), and “..” means the parent directory one level up. If it starts with “/”, it is an absolute path specified from the root directory; if it starts with none of these, “./” is regarded as omitted.
A relative path simply writes out the route from where you are now to where you want to go. First trace on the tree the path from the current directory to the target file (here B → A → D → E), write one “..” for each level you go up, and then join the names of the directories you go down into with “/”. The name of the directory you moved up to is already included in “..”, so do not write it again.