Setting and working with the working directory

At any point you can access and save files by entering the complete file path. To cut these expressions short, it is very useful to set a working directory, so that you only have to specify the sub-folder that you want to address.

If you do not specify a working directory, a default like the “Documents” folder will be used. To find out the place and content of the current working directory use the following commands:

pwd // display file path of current working directory
dir // display all documents and sub-folders of the current working directory

Once you have prepared your workspace, you can define this as your working directory. You can find the file path for example by clicking the explorer bar like this:

Screenshot

Change your directory to the prepared workspace by entering:

cd “folder/subfolder” // change working directory

Note:

  • In a dofile, setting the working directory is always one of the first steps before loading any data.
  • Make sure to embed your file path in “ “ if you have any blanks in the folder names as the folder will otherwise not be recognized
  • Always use “/” instead of “\” in your file path as backward slashes cause issues in some commands and cannot be read in all operating systems

Exercise

  1. Check what your default working directory is
  2. Set up a file structure as in the previous section, set the working directory to the “data” folder and inspect via the command line what the contents of the new working directory are.