図に示す階層構造において,カレントディレクトリが*印のディレクトリであるとき,相対パス指定で ..¥..¥B¥B によって指定したディレクトリと同じディレクトリを絶対パス指定したものはどれか。 - ルート - A - A - A - B - B - A - B - B - A - A* - B - B - A - B 〔ディレクトリ及びファイルの指定方法〕 (1) ファイルは,“ディレクトリ名¥…¥ディレクトリ名¥ファイル名”のように,経路上のディレクトリを順に“¥”で区切って並べた後に“¥”とファイル名を指定する。 (2) カレントディレクトリは“.”で表す。 (3) 1階層上のディレクトリは“..”で表す。 (4) 始まりが“¥”のときは,左端にルートディレクトリが省略されているものとする。 (5) 始まりが“¥”,“.”,“..”のいずれでもないときは,左端にカレントディレクトリ配下であることを示す“.¥”が省略されているものとする。
平成26年度 春期 ITパスポート試験 問68
This question's explanation and your answers so far.
問 68
Incorrectア
¥A¥B¥B goes down from the A directly under the root, so it is a directory in the left half of the tree. The * mark is in the right half (under the B directly below the root), and moving up with “..” can never take you across to the A side in the left half. This is the mistake you make when you misidentify the position of the current directory.
Incorrectイ
¥B is merely the position where you stop after applying “..” twice, that is ¥B¥A¥A → ¥B¥A → ¥B. It does not reflect the two remaining elements “¥B¥B,” which move down, so it is two levels short.
Incorrectウ
¥B¥B is the position you reach if, after moving up to ¥B, you go down with “B” only once. Two Bs stand side by side at the end of the relative path, so the downward move must be performed twice; this answer is one level short. It is the wrong answer you are likely to pick when you miscount the number of “..” steps and the number of downward steps.
- エ
正解 First, pin down where * is by writing it as an absolute path. In the tree of the figure, the A marked with * is reached by following Root → B → A → A, so the current directory is ¥B¥A¥A. Next, apply the relative path “..¥..¥B¥B” one element at a time from the left. (1) The first “..” moves up one level, giving ¥B¥A. (2) The second “..” moves up one more level, giving ¥B. (3) The following “B” is the B directly under the current position ¥B, giving ¥B¥B. (4) The last “B” is the B one more level down, giving ¥B¥B¥B. In the figure, the B under the root, the B under it, and the B under that one all really exist. Therefore the same directory expressed as an absolute path is ¥B¥B¥B, so エ is correct.
- An absolute path is a way of specifying a location starting from the root directory, while a relative path starts from the current directory. “.” refers to the current directory and “..” refers to the directory one level up.
- A reliable way to solve a relative path is to apply it one element at a time from the left, updating your current position as you go. Counting it in two separate stages — go up as many levels as there are “..” entries, then go down as many levels as there are remaining directory names — reduces mistakes.