# Change directory before running an external command

**URL:** <https://discourse.julialang.org/t/change-directory-before-running-an-external-command/59479>\
**Category:** General Usage\
**Tags:** shell, cmd\
**Created:** [April 17, 2021, 2:30pm UTC](https://discourse.julialang.org/t/change-directory-before-running-an-external-command/59479 "2021-04-17T14:30:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [April 17, 2021, 2:30pm UTC](https://discourse.julialang.org/t/change-directory-before-running-an-external-command/59479/1 "2021-04-17T14:30:09Z")

</div>

I have a julia file, say `FileIwantToRun.jl` in many folders/directories. I want to write a script that visits each of these directories and runs this file from those directories (it outputs a file that I want it to save in that folder). I tried the function shown below but get an error saying that:

`ERROR: IOError: could not spawn `julia16 FileIwantToRun.jl`: no such file or directory (ENOENT)`

When I manually visit this folders and run `julia16 FileIwantToRun.jl` it runs without any issues. Can you please point out what I am doing wrong? Thank you.

```julia
function runfile()
    for dest in destdirs 
        println("Running file in $(dest)")
        cd(dest) do 
            run(`julia16 $(FileIwantToRun.jl)`)
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [April 17, 2021, 3:07pm UTC](https://discourse.julialang.org/t/change-directory-before-running-an-external-command/59479/2 "2021-04-17T15:07:01Z")

</div>

I figured this out. The problem was that Julia did not know how to find `julia16` binary. If I give full path to that binary, it works.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [April 17, 2021, 3:11pm UTC](https://discourse.julialang.org/t/change-directory-before-running-an-external-command/59479/3 "2021-04-17T15:11:52Z")

</div>

Maybe you want the path to your julia16 in your PATH environment variable.

```julia
C:\bin\julia>cat ..\here.jl
println("there")

C:\bin\julia>cat here.jl
println("here")

C:\bin\julia>julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.6.0 (2021-03-24)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> for d in [".",".."]; cd(d) do; run(`julia here.jl`); end; end
here
there

```
