# How to correctly set up VS working directory on Windows for project with multiple subfolders?

**URL:** https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329
**Category:** VS Code
**Tags:** question
**Created:** [August 5, 2022, 8:45am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329 "2022-08-05T08:45:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tstoerk](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tstoerk](https://discourse.julialang.org/u/tstoerk)
#### Post date: [August 5, 2022, 8:45am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/1 "2022-08-05T08:45:15Z")

</div>

I am on Windows, trying to move from running Julia in Jupyter notebooks to directly running my code from VisualStudio.

I am working on a project that uses multiple modules (XXX.jl files) that live in one subfolder, but which draw on data files (YYY.csv) that live in another subfolder.

That is, my folder structure is: ..\project\modules and ..\project\data.

So far I have managed to set my general Julia working directory in VisualStudio to .…\project.

In my code (XXX.jl), I can load modules by including them via “…/modules/XXX.jl”.

However, when a module tries to access one of the data files in ..\project\data, I get an error: “ERROR: LoadError: ArgumentError: “…/data/YYY.csv” is not a valid file or doesn’t exist”

When I run the same code in Jupyter notebook with the same project working directory set everything runs smoothly, which makes me think this is an issue with my VS configuration.

Many thanks for helping, and apologies if this is not phrased correctly - it’s my first post.

---

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [August 5, 2022, 9:33am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/2 "2022-08-05T09:33:54Z")

</div>

Maybe you could print the output of `pwd()` to see the current working directory.  
Your Julia session of VS code probably has the root directory of your project as working directory:

- When you include modules it is with respect to the file location.
- When you load files it will be with respect to working directory.

In Jupyter notebooks, it will spawn a new Julia session for you which then has the file location as the working directory.

* * *

EDIT: I would do what @pfitzseb wrote 😃

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [August 5, 2022, 9:35am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/3 "2022-08-05T09:35:54Z")

</div>

Generally I’d recommend specifying paths relative to the current dir with e.g. `joinpath(@ __DIR__ , "..", "project", "modules)` instead of modifying `cwd`.

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [August 5, 2022, 10:45am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/4 "2022-08-05T10:45:44Z")

</div>

The last answer is a good one. There are a number of similarly helpful macros:  
[https://docs.julialang.org/en/v1/base/base/#Base.@\_\_DIR\_\_](https://docs.julialang.org/en/v1/base/base/#Base.@ __DIR__ )

---

<div class="post-metadata">

### Author: ![tstoerk](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tstoerk](https://discourse.julialang.org/u/tstoerk)
#### Post date: [August 5, 2022, 2:40pm UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/5 "2022-08-05T14:40:40Z")

</div>

Thank you all! The solution was simply to make the sub-directory in which XXX.jl lives the working directory.

This still is done via `cwd` - so room for me to experiment with @pfitzseb’s solution.

---

<div class="post-metadata">

### Author: ![tstoerk](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tstoerk](https://discourse.julialang.org/u/tstoerk)
#### Post date: [November 17, 2022, 4:27pm UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/6 "2022-11-17T16:27:08Z")

</div>

Thanks for the earlier answers. Unfortunately, the problem still comes back from time to time - why or under which conditions I don’t know.

I have to admit what @pfitzseb wrote above is beyond my current level of comprehension, similar to @jd-foster’s pointer to macros.

What @SteffenPL diagnoses above seems to hint at a problem in how Julia sessions within VisualStudio are set up - would anyone have a tutorial in very basic language on how to set these up properly in VisualStudio?

For reference:

(i) when I run ‘pwd()’ in a Julia session in VS, I correctly get …\project\ as the working directory.

(ii) the way I call the file in question is already by specifying paths relative to that working directory: ‘countries = CSV.read(“…/data/pattern-scaling.csv”, DataFrame).Country’

Many thanks

---

<div class="post-metadata">

### Author: ![tstoerk](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tstoerk](https://discourse.julialang.org/u/tstoerk)
#### Post date: [November 18, 2022, 9:30am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/7 "2022-11-18T09:30:13Z")

</div>

One additional piece of information I just discovered related to point (ii) above:

If I remove the “…/” bit before the relative path (“…/data/pattern-scaling.csv”), Julia in VS finds the file and everything runs - would anyone know what might cause this?

The current code with “…/” runs correctly on my collaborators machine (which I think is either Linux or MacOS).

---

<div class="post-metadata">

### Author: ![tstoerk](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tstoerk](https://discourse.julialang.org/u/tstoerk)
#### Post date: [November 22, 2022, 11:28am UTC](https://discourse.julialang.org/t/how-to-correctly-set-up-vs-working-directory-on-windows-for-project-with-multiple-subfolders/85329/8 "2022-11-22T11:28:25Z")

</div>

For posteriority I record the solution, which turned out to be simple:

Note that my path structure was:  
-Main folder  
–Subfolder 1  
–Subfolder 2

The Julia code lives in Subfolder 1, while the data the Julia code calls lives in Subfolder 2.

Through “…/”, the relative path goes up to the main folder first. By making Subfolder 2 the current working directory, all relative paths work as intendend.
