This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
How to | Insert a File Path
Whether it is for importing, exporting, or other operations, Mathematica must know where to look for files on your computer before it can use them. There are a number of directories that Mathematica automatically searches for files. However, when the files you want to use are not in these directories, you need to specify their location. Mathematica provides several convenient ways for doing this.
One way of telling Mathematica where to find a file or directory is to type in the full path.
For example, import the size of this image by typing in the full file path:
Click for copyable input
The parts of this file path are separated by the character, which is used in strings to represent the character, the file separator on the Windows operating system.
If you do not know the full file path, you can use the InsertFile Path menu item. This lets you use your computer's file system browser to select a file:
When using this menu item, you must select an individual file. Mathematica will not let you select a folder. To insert a folder path, select a file in that folder and manually delete the file name from the path.
Alternatively, you can use DirectoryName with the file name:
Click for copyable input
You can also insert the path of a folder or a file by simply using drag and drop in combination with a keyboard shortcut.
In Mac OS X, first navigate to the file or folder. Click and drag it over a notebook, and then hold down the Option key when releasing the mouse button:
In Windows, do the same thing except hold down the Ctrl+ Shift keys when releasing the mouse button. The cursor will change to indicate that a path will be inserted when you release the mouse button:
In Linux, the keyboard shortcut for inserting a file or folder path with drag and drop is Shift. However, depending on your file manager program, you may not see a change in the cursor. Even if the cursor does not change, holding Shift while dragging and dropping a file or folder will still insert the correct path.
In Windows and Linux, inserting a file or folder path with drag and drop will not work in versions prior to Mathematica 8.
To learn about programmatically constructing file and directory paths, see How to: Input and Construct File Names in Mathematica.
For information on identifying and changing the directories that Mathematica automatically uses when looking for files, see How to: Locate and Use Files.