# Working with multiple files

**URL:** https://discourse.julialang.org/t/working-with-multiple-files/5190
**Category:** General Usage
**Tags:** question, code-organization
**Created:** [August 2, 2017, 7:03pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190 "2017-08-02T19:03:47Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 7:03pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/1 "2017-08-02T19:03:47Z")

</div>

I’m missing something as far as how to work with multiple files.

I have a directory where I keep two \*.jl files, say “core.jl” and “scripts.jl” One has most of the core analytical code, the other has some very project specific scripts. At the top of scripts.jl, I have:

```julia
using DataFrames, Distributions, StatsBase, MyModule

```

where MyModule is in core.jl. If I run scripts.jl without running core.jl first, I get:

```julia
LoadError: ArgumentError: Module MyModule not found in current path.

```

I tried putting the following code at the top of scripts.jl (path edited for brevity):

```julia
if length(findin("C:\\MyProject17",LOAD_PATH)) == 0
  push!(LOAD_PATH,"C:\\MyProject17")
end

```

This had no effect.

If I run core.jl first, everything works fine, so this is more of an annoyance. In the off-chance this is an actual issue, happy to post there, but I figure I am most likely just missing something on how to properly link the files. I’m using Julia 0.6/Atom/Juno if it makes a difference.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 2, 2017, 7:11pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/2 "2017-08-02T19:11:45Z")

</div>

`include("core.jl")` in your script file

---

<div class="post-metadata">

### Author: ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)
#### Post date: [August 2, 2017, 7:24pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/3 "2017-08-02T19:24:24Z")

</div>

Just to further explain this point: if you put `include("core.jl")` in your script file, then each time you edit and reload the script file, the core routines will also get recompiled. That may or may not be desirable depending on the relative size of the files and how often each needs editing.

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 7:28pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/4 "2017-08-02T19:28:24Z")

</div>

It is a rather large module, so it would be ideal to not recompile each time. Also, when I do `include("core.jl")` I get the following error: .

```julia
LoadError: UndefVarError: dropNullsFromDF not defined

```

Where dropNullsFromDF is an exported function in core.jl and MyModule. I’d rather not write out MyModule.dropNullsFromDF or whatever function I am calling each time I use a function from MyModule.

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 8:31pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/5 "2017-08-02T20:31:16Z")

</div>

Solved (sort of). Having `include("core.jl")` AND `using MyModule` works, but with a couple of warnings on recompilation

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 2, 2017, 8:55pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/6 "2017-08-02T20:55:50Z")

</div>

In order for `using` to work without including the file, it needs to follow the structure of a package and be available in `LOAD_PATH`.

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 9:09pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/7 "2017-08-02T21:09:15Z")

</div>

I see, thank you. Just to be clear, the only way to avoid the warnings is to have a package? Is there any way to do this without setting something up on git?

I’m just looking for a light-weight way to work with multiple files without having to go through the overhead of registering it all on git and its version control (this is a mostly solo project).

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [August 2, 2017, 9:16pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/8 "2017-08-02T21:16:40Z")

</div>

> [@clinton](#):
>
> avoid the warnings is to have a package

You can’t avoid the warning if you changed the module.

> [@clinton](#):
>
> Is there any way to do this without setting something up on git?

Yes, by

> [@kristoffer.carlsson](#):
>
> follow the structure of a package and be available in LOAD\_PATH.

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 9:24pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/9 "2017-08-02T21:24:13Z")

</div>

I see, thank you.

I added the directory to load path. I’m less concerned about the standard replacing module warning and more concerned about the following:

```julia
WARNING: using MyModule.MyModule in module myScript conflicts with an existing identifier.

```

I’m fine with ignoring it if that’s what i need to do.

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 9:28pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/10 "2017-08-02T21:28:11Z")

</div>

Also, I noticed wrapping scripts.jl in a module of its own breaks this approach. Just to be clear, this is what I am running:

```julia
module myScript

if length(findin(pwd(),LOAD_PATH)) == 0
  push!(LOAD_PATH,pwd())
end

include("core.jl")
using DataFrames, StatsBase, Distributions, MyModule

println(myMethod())

end

```

Error:

```julia
LoadError: ArgumentError: Module MyModule not found in current path.
Run `Pkg.add("MyModule")` to install the MyModule package.
while loading C:\Users\Clinton\Dropbox\Projects\JuliaTest\scripts.jl, in expression starting on line 11
in require at base\loading.jl:398
in _require at base\loading.jl:428

```

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 9:57pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/11 "2017-08-02T21:57:17Z")

</div>

I think I got it- I put everything into the same module name as in some of the examples at [https://docs.julialang.org/en/stable/manual/modules/#modules-1](https://docs.julialang.org/en/stable/manual/modules/#modules-1). I think the similarities and differences between the C++ namespace and class construct and the module construct in Julia were throwing me off.

Thank you @yuyichao and @kristoffer.carlsson for the help and patience.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [August 2, 2017, 11:30pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/12 "2017-08-02T23:30:29Z")

</div>

> [@clinton](#):
>
> I tried putting the following code at the top of scripts.jl (path edited for brevity):
> 
> if length(findin(“C:\MyProject17”,LOAD\_PATH)) == 0  
> push!(LOAD\_PATH,“C:\MyProject17”)  
> end
> 
> This had no effect.

For a module to be found in LOAD\_PATH, it needs to be in a file with the same name.  
`MyModule` should be in `MyModule.jl`

So you could try changing filename `core.jl` to `MyModule.jl`, and inserting the following into `scripts.jl`:

```julia
thisdir = dirname(@ __FILE__ ())
any(path -> path==thisdir, LOAD_PATH) || push!(LOAD_PATH, thisdir)
using MyModule

```

---

<div class="post-metadata">

### Author: ![clinton](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@clinton](https://discourse.julialang.org/u/clinton)
#### Post date: [August 2, 2017, 11:45pm UTC](https://discourse.julialang.org/t/working-with-multiple-files/5190/13 "2017-08-02T23:45:42Z")

</div>

Beautiful! That worked well. Thank you
