2

In Erlang, the file module allows one to move the file cursor to a given position by file:position/2. But after performing an operation such as file:read_line/1, the cursor now moves.

Is there any way to get its current location?

Sorry if this seems silly, I'm new to Erlang and I cannot seem to find any relevant function in the module documentation to perform this. Any help will be much appreciated.

Hynek -Pichi- Vychodil
  • 26,174
  • 5
  • 52
  • 73

1 Answers1

4

To get the current file position, call file:position/2 with the atom cur as the second argument.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
  • I completely missed that in the docs. This will return {ok, NewPosition} where NewPosition is equal to the current position. Much appreciated. – Alan Rodas Bonjour Jun 18 '16 at 13:37