# SystemError:opening file Tensor1.txt: No such file or Directory

**URL:** <https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480>\
**Category:** New to Julia\
**Created:** [August 15, 2018, 3:34am UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480 "2018-08-15T03:34:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelord12](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@marcelord12](https://discourse.julialang.org/u/marcelord12)\
**Post date:** [August 15, 2018, 3:34am UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/1 "2018-08-15T03:34:49Z")

</div>

Hi guys, I’m trying to execute a script file, but I got a message of SystemError:opening file Tensor1.txt: No such file or Directory. Actually the file Tensor1.txt is there inside the same folder. I can’t figure out why Julia 0.6.4 is not reading the file. I’m running this script file on Atom 1.29.

The code is:

````julia

# MDP problem description

# Get transition matrices
Tensor = Dict()
Tensor["1"] = readdlm("Tensor1.txt")
Tensor["2"] = readdlm("Tensor2.txt")

# Get reward function
Rewards = Dict()
Rewards["1"] = readdlm("Rewards1.txt")
Rewards["2"] = readdlm("Rewards2.txt")

# State space description
States = Dict()
States["#states"] = size(Tensor["1"],1)
States["FeatSize"] = [2,162]

Actions = Dict()
Actions["#actions"] = 2

Constraints = Dict()
Constraints["#constraints"] = 1
Constraints["States"] = [52]

# Initial condition
init = 1
λ = 0.7

VXpolicy = CMDP(States,Actions,
                Tensor,Rewards,
                λ,init,zeros(3),Constraints)

(Values,Policy) = SolveCMDP(VXpolicy);

TotalStates = States["#states"]

MC = zeros(TotalStates,TotalStates)

for i = 1:TotalStates
   ind = Policy[i]
   MC[i,:] = Tensor["$(ind)"][i,:]
end
``

``` LoadError: e[91mSystemError: opening file Tensor1.txt: No such file or directorye[39m
while loading /Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/LP/Sample.jl, in expression starting on line 7
#systemerror#44 at error.jl:64 [inlined]
systemerror(::String, ::Bool) at error.jl:64
open(::String, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at iostream.jl:104
open(::Base.#readstring, ::String) at iostream.jl:150
#readdlm_auto#11(::Array{Any,1}, ::Function, ::String, ::Char, ::Type{T} where T, ::Char, ::Bool) at datafmt.jl:134
#readdlm#7 at datafmt.jl:81 [inlined]
readdlm(::String, ::Char, ::Char) at datafmt.jl:81
#readdlm#5(::Array{Any,1}, ::Function, ::String) at datafmt.jl:64
readdlm(::String) at datafmt.jl:64
include_string(::String, ::String) at loading.jl:522
include_string(::Module, ::String, ::String) at Compat.jl:88
(::Atom.##112#116{String,String})() at eval.jl:109
withpath(::Atom.##112#116{String,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
hideprompt(::Atom.##111#115{String,String}) at repl.jl:67
macro expansion at eval.jl:106 [inlined]
(::Atom.##110#114{Dict{String,Any}})() at task.jl:80```
````

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [August 15, 2018, 8:34am UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/2 "2018-08-15T08:34:33Z")

</div>

I think `julia-0.6` looks up that file in the current working directory (`pwd()`) not in the `/Users/marcelord12/Documents/phd2018/mppo/thesis/MDP/LP/` .

> [@marcelord12](#):
>
> Actually the file Tensor1.txt is there inside the same folder

Which folder do you mean?

---

<div class="post-metadata">

**Author:** ![marcelord12](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@marcelord12](https://discourse.julialang.org/u/marcelord12)\
**Post date:** [August 15, 2018, 12:23pm UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/3 "2018-08-15T12:23:10Z")

</div>

Thanks, but I was runing the .jl script file code in the same directory where I saved Tensor1.txt. I thought that is the Current Directory.

What shall I do to fix the error?

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [August 15, 2018, 12:57pm UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/4 "2018-08-15T12:57:05Z")

</div>

You can put `pwd()` at the begining of jl file to see current directory. Maybe use absolute path if julia confuses which folder it should load the file?

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [August 15, 2018, 1:17pm UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/5 "2018-08-15T13:17:23Z")

</div>

I tried this

```bash
~$ cat > test.txt
LTMS
^C
~$ cat > Projects/Julia/trial.jl
pwd()   
f=open("test.txt","r+")  
t = readlines(f)   
close(f)   
^C
~$ julia

julia> include("Projects/Julia/trial.jl")

julia> t
1-element Array{String,1}:
 "LTMS"

...

~$ mv test.txt Projects/Julia/test.txt
~$ julia

julia> include("Projects/Julia/trial.jl")
ERROR: LoadError: SystemError: opening file test.txt: No such file or directory
Stacktrace:
 [1] #systemerror#39(::Nothing, ::Function, ::String, ::Bool) at ./error.jl:106
 [2] systemerror at ./error.jl:106 [inlined]
 [3] #open#297(::Bool, ::Bool, ::Nothing, ::Nothing, ::Nothing, ::Function, ::String) at ./iostream.jl:283
 [4] #open at ./none:0 [inlined]
 [5] open(::String, ::String) at ./iostream.jl:339
 [6] top-level scope at none:0
 [7] include at ./boot.jl:317 [inlined]
 [8] include_relative(::Module, ::String) at ./loading.jl:1038
 [9] include(::Module, ::String) at ./sysimg.jl:29
 [10] include(::String) at ./client.jl:398
 [11] top-level scope at none:0
in expression starting at ~/Projects/Julia/trial.jl:2

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [August 15, 2018, 3:26pm UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/6 "2018-08-15T15:26:58Z")

</div>

Current directory is by default the directory from which you start Julia. If you want to find a file in the same directory as a file you load, `@ __DIR__ ` is probably what you look for. Try

```julia
f = open(joinpath(@ __DIR__ , "test.txt"), "r+")

```

in your test script.

---

<div class="post-metadata">

**Author:** ![marcelord12](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@marcelord12](https://discourse.julialang.org/u/marcelord12)\
**Post date:** [August 15, 2018, 11:05pm UTC](https://discourse.julialang.org/t/systemerror-opening-file-tensor1-txt-no-such-file-or-directory/13480/7 "2018-08-15T23:05:08Z")

</div>

Thanks\> I think it has worked. But I got an unexpected error:  
WARNING: Problem status UnknownError; solution may be inaccurate.
