anony_std
anony_std

Reputation: 29

Erlang : exception error: no match of right hand side value {error,enoent} while reading a text file

I am currenly working on an erlang project and stuck in reading the file. I want to read a text file which is in the /src folder where all the erlang and a text file are in the same structure. Then too, I am not being able to read the file despite of specifying file paths. Any help would be appreciated.

start() ->
    {ok,DataList} = file:consult("Calls.txt"),
    io:format("** Calls to be made **"),
    io:fwrite("~w~n",[DataList]).

The data file stores contents like : {john, [jill,joe,bob]}.

Upvotes: 1

Views: 484

Answers (3)

Mridul Advani
Mridul Advani

Reputation: 21

If you need to use src/call.txt, then this simply means that your IDE (or you) has created a src folder in which the calls.txt file has been placed. At the same time, the IDE is using a path that only includes the top level folder (i.e., the root folder for the IDE project). So src/call.txt must be used in that case. This isn’t a problem with Erlang, or even the IDE. It’s just the way your project is set up.

You can do either of two things. Move the calls.txt file up one level in the IDE file manager, so that it can be referenced as calls.txt, not src/call.txt. You can also just change the path to “calls.txt” before you run it from the command line.

Upvotes: 1

vkatsuba
vkatsuba

Reputation: 1459

Try add folder name to the path or try set full patch to the file:

1> {ok,DataList} = file:consult("src/Calls.txt").

Notes: the error {error,enoent} mean that the file does not exist or you don't have a rights to read/write current file, for this case need set 777 rights or similar.

Upvotes: 1

choroba
choroba

Reputation: 242443

enoent means "Error: No Entry/Entity". It means the file couldn't be found. When I try your code, it works correctly and outputs

[{john,[jill,joe,bob]}]

Upvotes: 0

Related Questions