Using Relative Paths in Hero

When working with file systems, paths are used to locate files and directories. These paths can be absolute or relative. Understanding relative paths can make it easier to work with files without needing to know the full absolute path. In particular, placing files relative to the workflow file makes it easier to share data and workflows without the risk of having broken paths to data.

What is a Relative Path in Hero?

A relative path specifies the location of a file or directory relative to the current directory where your workflow is stored. This is different from an absolute path, which specifies the complete location starting from the root of the file system.

For example:

In the relative path example, data/diff1000.nii.gz refers to the diff1000.nii.gz file located inside the data directory. You can use this relative path in Hero if your workflow file is saved in the C:/Users/HeroUser/Documents/diff_analysis folder.

Using ./ in Relative Paths

The ./ symbol represents the current directory. In the example above you can also write the relative path as ./data/diff1000.nii.gz.

Example:

When importing data from file, relative paths are very convenient. The picture below shows the settings for a Import Nifti node when the data is placed relative to the workflow.

Node Icon

Using Just the Last Part of the Path

If you are referencing a file in the same directory you have your workflow in, you can simply use the last part of the path—the file or folder name.

Example:

If the nifti file in the example above is in the same directory as the workflow, you can use diff1000.nii.gz for your path setting. No need to specify the full or even the relative path if the file is in the current directory.

Node Icon

Moving Around the Folder Tree: . and ..

To navigate between different directories in a relative manner, you can use two important symbols: . and ...

Using .. to Move Up a Directory

The .. symbol allows you to move up one level in the directory tree. If you are in a subdirectory and want to reference something in the parent directory, use .. in your path.

Example:

Let's say your workflow is in C:/Users/HeroUser/Documents/diff_analysis and want to access the file C:/Users/HeroUser/Documents/diff1000.nii.gz. You would use:

Node Icon

In this case:

Going Multiple Levels Up

You can chain .. to move up multiple levels in the folder tree. Each .. moves you up one level.

Example:

If your workflow is in C:/Users/HeroUser/Documents/diff_analysis and want to access a file in C:/Users/HeroUser, you can write:

../../diff1000.nii.gz

Summary of Common Path Symbols:

Support

All nodes that imports or exports from and to files support relative paths. Note that your workflow must be saved for relative paths to be meaningful and work.