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:
- Absolute path:
C:/Users/HeroUser/Documents/diff_analysis/data/diff1000.nii.gz
- Relative path:
data/diff1000.nii.gz
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.
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.
Moving Around the Folder Tree: .
and ..
To navigate between different directories in a relative manner, you can use two important symbols: .
and ..
.
.
refers to the current directory...
refers to the parent directory (the directory one level up).
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:
In this case:
..
takes you up toC:/Users/HeroUser/Documents
diff1000.nii.gz
specifies the file you want to access.
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
- The first
..
moves up fromdiff_analysis
toDocuments
. - The second
..
moves up fromDocuments
toHeroUser
.
Summary of Common Path Symbols:
.
: Refers to the current directory...
: Refers to the parent directory (one level up)../<relative_path>
: Refers to a file or directory in the current directory.<relative_path>
: Refers to a file or directory in the current directory.../<relative_path>
: Moves up to the parent directory and then accesses a file or folder.
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.
Copyright © 2025, Hero Imaging AB