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

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:

# 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,

(Values,Policy) = SolveCMDP(VXpolicy);

TotalStates = States["#states"]

MC = zeros(TotalStates,TotalStates)

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

``` 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```

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/ .

Which folder do you mean?

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?

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?

I tried this

~$ cat > test.txt
~$ cat > Projects/Julia/trial.jl
t = readlines(f)   
~$ julia

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

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


~$ 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
 [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

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

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

in your test script.

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