How to | Locate and Use Files
The Wolfram Language offers support for a large number of file formats for importing, exporting, or other operations. It has several standard locations where it looks for files. You can change these locations to place other directories in the Wolfram Language's default search path.
The Wolfram Language is able to use files without the full file path specified. However, the files must be located in one of the directories that the Wolfram Language searches for files.
By default, the Wolfram Language is able to use files in the directories that appear in $Path:
The Wolfram Language is also able to use files located in your current working directory without a full file path.
View your current working directory by evaluating Directory[]:
You can see a list of all files in the current working directory by evaluating FileNames[]:
You can view the file names you want by using wildcards:
There are a number of methods you can use to access a file if it is in a directory that is not on $Path or in your current working directory.
For example, you can specify the full path of a file or folder that you want to use. See How to: Insert a File Path to view the different methods available for doing this.
Or, use SetDirectory to change your current working directory:
To use a file that is in one of the directories on $Path or your current working directory, you only need to specify the name of the file.
Import the file "noise.jpg" from the current working directory:
Use ResetDirectory[] to reset the current working directory to its previous value:
You can also append a directory to $Path.
Use AppendTo with $Path and the directory path:
You can now import "noise.jpg" without changing your current working directory:
Note that the change to $Path is temporary, and the value is reset when you restart the Wolfram System or the kernel.
To make the change permanent, you can add the previous AppendTo command to one of the following two init.m files. Here, FileNameJoin is used to construct a full file path from $UserBaseDirectory and $BaseDirectory:
Just like $Path, $UserBaseDirectory, and $BaseDirectory, other system variables can be used to construct file paths. Some commonly used system variables that represent directories are $RootDirectory, $HomeDirectory, and $InstallationDirectory.