Skip to content

Commit 27d9580

Browse files
committed
Added File.listdir! variation
1 parent a8c89e3 commit 27d9580

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/elixir/lib/file.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,21 @@ defmodule File do
921921
end
922922
end
923923

924+
925+
@doc """
926+
Get list of files in directories in `dir`.
927+
928+
Raises File.Error in case of an error.
929+
"""
930+
def listdir!(dir) do
931+
case F.list_dir(dir) do
932+
{ :ok, file_list } -> { :ok, Enum.map file_list, :unicode.characters_to_binary(&1) }
933+
{ :error, reason } ->
934+
raise File.Error, reason: reason, action: "list directory", path: :unicode.characters_to_binary(dir)
935+
end
936+
end
937+
938+
924939
@doc """
925940
Closes the file referenced by `io_device`. It mostly returns `:ok`, except
926941
for some severe errors such as out of memory.

0 commit comments

Comments
 (0)