Operating System | File Directory | Path Name

Prerequisite – File Systems

Hierarchical Directory Systems –

Directory is maintained in the form of a tree.Each user can have as many directories as are needed so, that files can be grouped together in natural way.

Advantages of this structure:

  • Searching is efficient
  • Groping capability of files increase

When the file system is organized as a directory tree, some way is needed for specifying file names.

Two different methods are commonly used:

  1. Absolute Path name – In this method, each file is given an absolute path name consisting of the path from the root directory to the file. As an example, the path /usr/ast/mailbox means that the root directory contains a subdirectory usr, which in turn contains a subdirectory ast, which contains the file mailbox.

    Absolute path names always start at the root directory and are unique.

    In UNIX the components of the path are separated by /. In Windows the separator is \.
    Windows \usr\ast\mailbox
    UNIX /usr\ast\mailbox

  2. Relative Path name – This is used in conjunction with the concept of the working directory (also called the current directory).A user can designate one directory as the current working directory, in which case all path names not beginning at the root directory are taken relative to the working directory.

    For example, if the current working directory is /usr/ast, then the file whose absolute path is /usr/ast/mailbox can be referenced simply as mailbox.
    In other words, the UNIX
    command : cp /usr/ast/mailbox /usr/ast/mailbox.bak
    and the command : cp mailbox mailbox.bak
    do exactly the same thing if the working directory is /usr/ast.

When to use which approach ?
Some programs need to access a specific file without regard to what the working directory is. In that case, they should always use absolute path names. For example, a spelling checker might need to read /usr/lib/dictionary to do its work. It should use the full, absolute path name in this case because it does not know what the working directory will be when it is called. The absolute path name will always work, no matter what the working directory is.

Of course, if the spelling checker needs a large number of files from /usr/lib, an alternative approach is for it to issue a system call to change its working directory to /usr/lib, and then use just dictionary as the first parameter to open. By explicitly changing the working directory, it knows for sure where it is in the directory tree, so it can then use relative paths.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Practice Tags :
Article Tags :
Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:

0 Average Difficulty : 0/5.0
No votes yet.

User Actions