The Code Ocean filesystem
The key file paths to know are
/data , and
/results. These correspond to the three panes in your workspace: Code, Data, and Results.
When possible, use relative paths –
../results – which will make it easier for users who download your code to run things on their own computer.
When you run your code, the initial working directory will be
/code. If you use relative paths, you will rarely need to refer to it. If you have code in a subfolder, don't forget to add
.. as necessary, e.g.
load('../../data/my_data.csv'). This would go up two parent directories and then look for
Use symbolic links to alias paths. This is useful if you have numerous hardcoded paths that would be time-consuming to change manually.
Consider the following shell script (typically called
run.sh on Code Ocean):
ln -s /data ./input_images
python -u demo
ln -s command creates a link that points to
/data where the code might otherwise look for files in
Note: if the path your code is expecting includes non-existing folders, you'll need to create them first using
mkdir -p /results/analysis_one/fig1
ln -s /results/analysis_one/fig1 /code/fig1
See this Linux Manual page for more information.