How to | Insert a File Path

Whether it is for importing, exporting, or other operations, the Wolfram Language must know where to look for files on your computer before it can use them. There are a number of directories that the Wolfram Language automatically searches for files. However, when the files you want to use are not in these directories, you need to specify their location. The Wolfram Language provides several convenient ways for doing this.

This page requires that JavaScript be enabled in your browser.
Learn how »

One way of telling the Wolfram System 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:

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 Insert File 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. The Wolfram System 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:

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 key when releasing the mouse button:

In Windows, do the same thing except hold down the 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 . However, depending on your file manager program, you may not see a change in the cursor. Even if the cursor does not change, holding 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 the Wolfram Language.

For information on identifying and changing the directories that the Wolfram System automatically uses when looking for files, see How to: Locate and Use Files.