Issue loading files several folders deep

BlitzMax Forums/BlitzMax Beginners Area/Issue loading files several folders deep

coffeedotbean(Posted 2015) [#1]
I don't know why this fails, I am trying to load a file using ReadSteam that is two folders inside the folder that my .bmx and .exe file are.

If I put the file in the same folder as my .bmx and .exe it reads fine.

ofc I have checked the file paths and so on and they're correct.

All Fail
Local fileIn:TStream = ReadStream("/folder1/folder2/myfile.txt")
Local fileIn:TStream = ReadStream("folder1/folder2/myfile.txt")
Local fileIn:TStream = ReadStream("\folder1\folder2/myfile.txt")
Local fileIn:TStream = ReadStream("folder1\folder2/myfile.txt")
Local fileIn:TStream = ReadStream(CurrentDir()+"\folder1\folder2\myfile.txt")


Works
Local fileIn:TStream = ReadStream("myfile.txt")	


I tried using back slashes, removing the fist slash, using currentdir() and manually using the full system path but nothing helps, stumped now?!


Henri(Posted 2015) [#2]
Hi,

try this:
Local fileIn:TStream = ReadStream(CurrentDir() + "/folder1/folder2/myfile.txt")


-Henri


coffeedotbean(Posted 2015) [#3]
nope


Grisu(Posted 2015) [#4]
Why not use LoadText()?

Read the whole file at once.
file=LoadText("Incbin::./data/text_"+lang+".txt")  

And then split it into lines and get your data.
For Local line:String=EachIn file.split("~n")



coffeedotbean(Posted 2015) [#5]
Also doesn't work, however I noticed the '.' after the incbin in your path and now

Local fileIn:TStream = ReadStream("./folder1/folder2/myfile.txt")


works. I'll stick to stream unless there are advantages to using LoadText?

[EDIT]
Well I though it worked but I had the file in the same folder as my .bmx and .exe and for some reason it loads fine if its in there but I'm calling the file from another folder?! This is just bizzare


Henri(Posted 2015) [#6]
What does it show if you run this:
Print CurrentDir() + "/folder1/folder2/myfile.txt"
Are you running in Windows ?

-Henri


coffeedotbean(Posted 2015) [#7]
@Henri

Yes Windows and path looks correct when I print it to console as you advise.

But I found the issue, I forget I was load a second file using a value from the first text file but I was omitting the path and just calling the filename. Once I added the path its all fine.

A silly little mistake but has stumped me for hours.