# Behavior of cd() in Julia script

**URL:** <https://discourse.julialang.org/t/behavior-of-cd-in-julia-script/48532>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 17, 2020, 5:33am UTC](https://discourse.julialang.org/t/behavior-of-cd-in-julia-script/48532 "2020-10-17T05:33:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZZP12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zzp12/32/5095_2.png) [@ZZP12](https://discourse.julialang.org/u/ZZP12)\
**Post date:** [October 17, 2020, 5:33am UTC](https://discourse.julialang.org/t/behavior-of-cd-in-julia-script/48532/1 "2020-10-17T05:33:17Z")

</div>

Hi, I have a Julia script as below:

```julia
    generate_default_project("./default1")
    make_julia_model("./default1/Network.vff", "./default2")

    println(pwd())
    cd("./default2/")
    println(pwd())
    println("run the model")
    include("default2/Static.jl") 

```

The 1st line creates a folder `./default1`, and the 2nd line generates some Julia scripts and puts them under folder `./default2`.  
The output from the 1st `println(pwd())` is the absolute path of `./`, and the 2nd one is of `./default2`.  
My question is on the last line. Here `Static.jl` is a script under `./default2`, and the 2nd `println(pwd())` indicates that the cwd is `./default2`.  
But if I tried `include("./Static.jl")`, it just does not work.  
Can anyone explain what is happening here? Thanks much!  
I am using Julia1.5 on Ubuntu 18.04.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 17, 2020, 9:35am UTC](https://discourse.julialang.org/t/behavior-of-cd-in-julia-script/48532/2 "2020-10-17T09:35:45Z")

</div>

You may find this discussion helpfull:

> [@Include command inconsistent with isfile result](https://discourse.julialang.org/t/include-command-inconsistent-with-isfile-result/26578):
>
> I am having trouble to include a file. More precisely isfile(fi) returns true, but include(fi) errors ERROR: LoadError: could not open file C:\temp\a\SomePackage\src\src\file.jl I created an MWE here. I simply run julia --startup-file=no --track-allocation=user mwe\_include\_error.jl in PowerShell (from the src directory) Is this expected not to work? It is quite irritating that isfile returns true, but the include command fails.

In short, quoted from @Tamas_Papp

> [@Include command inconsistent with isfile result](https://discourse.julialang.org/t/include-command-inconsistent-with-isfile-result/26578/15):
>
> `include` operates relative to `@ __DIR__ ` , which has nothing to do with the “current directory”

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 17, 2020, 10:37am UTC](https://discourse.julialang.org/t/behavior-of-cd-in-julia-script/48532/3 "2020-10-17T10:37:56Z")

</div>

To elaborate on what @oheil said above, it’s _always_ best to pass to `include` absolute paths, and also use `joinpath` to write paths, which takes care of different path separators across different operating systems.

---

<div class="post-metadata">

**Author:** ![ZZP12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zzp12/32/5095_2.png) [@ZZP12](https://discourse.julialang.org/u/ZZP12)\
**Post date:** [October 18, 2020, 7:11pm UTC](https://discourse.julialang.org/t/behavior-of-cd-in-julia-script/48532/4 "2020-10-18T19:11:37Z")

</div>

Thanks! This is very helpful!
