# Working directory of Slicer

**URL:** <https://discourse.slicer.org/t/working-directory-of-slicer/6248>\
**Category:** Development\
**Created:** [March 22, 2019, 1:57pm UTC](https://discourse.slicer.org/t/working-directory-of-slicer/6248 "2019-03-22T13:57:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.slicer.org/u/Alex1)\
**Post date:** [March 22, 2019, 1:57pm UTC](https://discourse.slicer.org/t/working-directory-of-slicer/6248/1 "2019-03-22T13:57:07Z")

</div>

Hi, I always have the problem with the working directory of Slicer.  
when I use

> nrrd.write(filename,data)

I have no idea where my filename.nrrd is stored.  
And everytime I try to load a model or file to Slicer, the relative path(./directory) won’t work. So I have to use the full path. Is there a solution to this problem?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 22, 2019, 1:58pm UTC](https://discourse.slicer.org/t/working-directory-of-slicer/6248/2 "2019-03-22T13:58:37Z")

</div>

Non-console applications often do not have the notion of a “working directory”. You need to use absolute paths.

You can construct absolute paths from various directories, for example:

- `slicer.mrmlScene.GetRootDirectory()`: all nodes are saved relative to this path
- `slicer.app.temporaryPath`: write-able folder, you can use this to store any temporary data
- `slicer.app.slicerHome`: Slicer core binary folder
- `slicer.app.extensionsInstallPath`: Slicer extensions folder
- `slicer.modules.sampledata.path`: path of a scripted module (in this example: Sample Data module)

You can also pass any folder name to Slicer via the command-line. For example:

`"c:\Program Files\Slicer 4.10.1\Slicer.exe" --python-code "myDataDir='%cd%';loadVolume(myDataDir+'vol.nrd'); (do some processing here...); saveNode(someNode,myDataDir+'processed.nrrd')"`

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.slicer.org/u/Alex1)\
**Post date:** [March 22, 2019, 3:21pm UTC](https://discourse.slicer.org/t/working-directory-of-slicer/6248/3 "2019-03-22T15:21:33Z")

</div>

Hi, thanks for the answer. This is a very clear explanation. But I still have some problem here.  
In my scripted module, I got an array and I want to save it as a .nrrd file. I used nrrd.write but I still can’t find my file. I tried to look it up in slicer.modules.sampledata.path, but it’s not there. Where is it or how can I load this file to Slicer?

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 22, 2019, 3:27pm UTC](https://discourse.slicer.org/t/working-directory-of-slicer/6248/4 "2019-03-22T15:27:13Z")

</div>

If you have a numpy array and you want to show it as an image in Slicer then you don’t need to write it to file. You can directly write it to a volume node using [slicer.util.updateVolumeFromArray](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.updateVolumeFromArray).

if you want to write a temporary file, you can use `slicer.app.temporaryPath`, for example:

```
slicer.util.saveNode(someVolumeNode, slicer.app.temporaryPath+'/tempABC.nrrd')
```

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.slicer.org/u/Alex1)\
**Post date:** [March 22, 2019, 4:00pm UTC](https://discourse.slicer.org/t/working-directory-of-slicer/6248/5 "2019-03-22T16:00:01Z")

</div>

Hi, Thanks for your help. This is an awesome solution.
