When typing a path at the DOS prompt What symbol do you use to separate directory names from other directory names or file names?

A path is a unique location to a file or a folder in a file system of an OS.A path to a file is a combination of / and alpha-numeric characters.

Absolute Path-name

An absolute path is defined as the specifying the location of a file or directory from the root directory(/).
To write an absolute path-name:

  • Start at the root directory ( / ) and work down.
  • Write a slash ( / ) after every directory name (last one is optional)
  • For Example :

    $cat abc.sql
    

    will work only if the fie “abc.sql” exists in your current directory. However, if this file is not present in your working directory and is present somewhere else say in /home/kt , then this command will work only if you will use it like shown below:

    cat /home/kt/abc.sql
    

    In the above example, if the first character of a pathname is /, the file’s location must be determined with respect to root. When you have more than one / in a pathname, for each such /, you have to descend one level in the file system like in the above kt is one level below home, and thus two levels below root.

    An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory.

    Relative path

    Relative path is defined as the path related to the present working directly(pwd). It starts at your current directory and never starts with a / .

    To be more specific let’s take a look on the below figure in which if we are looking for photos then absolute path for it will be provided as /home/jono/photos but assuming that we are already present in jono directory then the relative path for the same can be written as simple photos.

    When typing a path at the DOS prompt What symbol do you use to separate directory names from other directory names or file names?

    Using . and .. in Relative Path-names

    UNIX offers a shortcut in the relative pathname– that uses either the current or parent directory as reference and specifies the path relative to it. A relative path-name uses one of these cryptic symbols:

    .(a single dot) - this represents the current directory.
    ..(two dots) - this represents the parent directory. 

    Now, what this actually means is that if we are currently in directory /home/kt/abc and now you can use .. as an argument to cd to move to the parent directory /home/kt as :

    $pwd
    /home/kt/abc
    $cd ..               ***moves one level up***
    $pwd
    /home/kt
    

    NOTE:Now / when used with .. has a different meaning ;instead of moving down a level,it moves one level up:

      
    $pwd
    /home/kt/abc        ***moves two level up***
    $cd ../..
    $pwd
    /home
    

    Example of Absolute and Relative Path

    Suppose you are currently located in home/kt and you want to change your directory to home/kt/abc. Let’s see both the absolute and relative path concepts to do this:

    1. Changing directory with relative path concept :
      $pwd
      /home/kt
      $cd abc                   
      $pwd
      /home/kt/abc         
      
    2. Changing directory with absolute path concept:
      $pwd
      /home/kt
      $cd /home/kt/abc
      $pwd
      /home/kt/abc
      

    This article is contributed by Dimpy Varshni. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to . 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.

Construct Valid Path and File Names

Specify Path Names

A path name specifies file locations, for example, C:\work\my_data (on Microsoft® Windows® platforms) or /usr/work/my_data (on Linux® or Mac platforms). If you do not specify a path name when accessing a file, MATLAB® first searches in the current folder. To indicate a file in a particular location, specify a path name.

Path name specifications differ, depending on the platform on which you are running MATLAB. Use the fullfile function to construct path names in statements that work on any platform. This function is particularly useful when you provide code to someone using it on a platform other than your own.

fullfile inserts platform-specific file separators where necessary. The file separator character is the symbol that distinguishes one folder level from another in a path name. A forward slash (/) is a valid separator on any platform. A backward slash (\) is valid only on Microsoft Windows platforms. In the full path to a folder, the final slash is optional. Type filesep in the Command Window to determine the correct file separator character to use on your platform.

To identify the platform on which MATLAB is currently running, use the ismac, ispc, and isunix functions.

Characters Within File and Folder Names

File names must start with a letter, and can contain letters, digits, or underscores.

Avoid using accent characters such as umlauts or circumflexes in path names. MATLAB might not recognize the path. In addition, attempts to save a file to such a path might result in unpredictable behavior.

If a path or file name contains spaces, enclose the input in single quotes. For example:

load 'filename with space.mat'

or

load('filename with space.mat')

Absolute and Relative Path Names

MATLAB always accepts absolute path names (also called full path names), such as I:/Documents/My_Files or /users/myuserid/Homework/myfile.m. An absolute path name can start with any of the following:

  • UNC path '\\'.

  • Drive letter, on Microsoft Windows platforms, such as C:\.

  • '/' character on Linux platforms.

Some MATLAB functions also support relative path names. Unless otherwise noted, the path name is relative to the current folder. For example:

  • myfile.m refers to the myfile.m file in the current folder.

  • myfolder refers to the myfolder folder in the current folder.

  • ../myfolder/myfile.m refers to the myfile.m file in the myfolder folder, where myfolder is at same level as the current folder. Each repetition of ../ at the beginning of the path moves up an additional folder level.

Tip

If multiple documents are open and docked in the Editor, you can copy the absolute path of any of these documents to the clipboard. This practice is useful if you need to specify the absolute path in another MATLAB tool or an external application. Right-click the document tab, and then select .

Partial Path Names in MATLAB

A partial path name is the last portion of a full path name for a location on the MATLAB search path. Some functions accept partial path names.

Examples of partial path names are: matfun/trace, private/cancel, and demos/clown.mat.

Use a partial path name to:

  • Specify a location independent of where MATLAB is installed.

  • Locate a function in a specific toolbox when multiple toolboxes contain functions with that name. For example, to open the file for the set function in the Database Toolbox™ product, type:

  • Locate method files. For example, to check if a plot method exists for the time series object, type:

    Specifying the at sign character (@) in method folder names is optional.

  • Locate private and method files, which sometimes are hidden.

Be sure to specify enough of the path name to make the partial path name unique.

Maximum Length of Path Names in MATLAB

The maximum length allowed for a path name depends on your platform.

For example, on Microsoft Windows platforms:

  • The maximum length is known as MAX_PATH.

  • You cannot use an absolute path name that exceeds 260 characters.

  • For a relative path name, you might need to use fewer than 260 characters. When the Windows operating system processes a relative path name, it can produce a longer absolute path name, possibly exceeding the maximum length.

If you get unexpected results when working with long path names, use absolute instead of relative path names. Alternatively, use shorter names for folders and files.

Case Sensitivity of File Names

In general, it is best to specify path and case precisely when specifying a file name.

Case Sensitivity When Calling Functions

You call function files by specifying the file name without the file extension. MATLAB returns an error if it cannot find a case-sensitive match on the search path. By default, MATLAB suggests a function with the correct case.

When multiple files have the same name, MATLAB follows precedence rules to determine which to call. For more information, see Function Precedence Order.

Case Sensitivity When Loading and Saving Files

Linux platforms File names are case sensitive.

  • When loading or reading from a file, specify the file name using the correct case.

  • When saving or writing to a file, MATLAB saves the file in the case you specify. Two files with the same name, but different cases can exist in the same folder.

Windows platforms — File names are case insensitive. The Windows operating system considers two files with the same name to be the same file, regardless of case. Therefore, you cannot have two file names that differ only by case in the same folder.

  • When loading or reading from a file, MATLAB accesses the file with the specified name that is higher on the search path, regardless of case. For example, if you attempt to load MYFILE and myfile.mat is higher on the search path than MYFILE.MAT, then MATLAB loads myfile.mat without warning that there is a case mismatch.

  • When saving or writing to a file, if you specify a file name that already exists in the folder, MATLAB accesses the existing file without warning. For example, if you save data to a file named myfile using the save function, and MYFILE.mat already exists in the folder, the data replaces the contents of MYFILE.mat. However, the file name remains MYFILE.mat.

See Also

filesep | fullfile | which | ismac | ispc | isunix

  • What Is the MATLAB Search Path?

How do you check the path of the current directory and traverse it to different paths using different options in Unix?

The answer is the pwd command, which stands for print working directory. The word print in print working directory means “print to the screen,” not “send to printer.” The pwd command displays the full, absolute path of the current, or working, directory.

Which command changes the current working directory to a different directory?

Use the cd command to move from your present directory to another directory. You must have execute (search) permission in the specified directory.

What is the path of home directory in Linux?

/home: We can use the /home as the default path for Linux Home Directory.

How do you go to a specific directory in Linux?

Navigate directories. Open a window, double-click on a folder, and then double-click on a sub-folder. Use the Back button to backtrack. The cd (change directory) command moves you into a different directory.