aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/c.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-05-22 11:39:13 +0200
committerBjörn Gustavsson <[email protected]>2013-05-22 11:54:37 +0200
commit67d83e15fdee068217df7f14a32fb901d7d4d91b (patch)
tree081b55a57e9d41494694e2b74eda30d6a2d57a05 /lib/stdlib/src/c.erl
parent2886d9937990c3465671b59d744f6bacd43545c8 (diff)
downloadotp-67d83e15fdee068217df7f14a32fb901d7d4d91b.tar.gz
otp-67d83e15fdee068217df7f14a32fb901d7d4d91b.tar.bz2
otp-67d83e15fdee068217df7f14a32fb901d7d4d91b.zip
Teach c:ls/1 to show non-directory files
In an email to erlang-questions, Bengt Kleberg wrote: When I use c:ls/1 it reminds me so much of Unix "ls" that I expect c:ls("filename") to work. The resulting error surprises me every time (not the same day). While teaching c:ls/1 to show non-directory files, update the error handling to make use of the POSIX error codes from file:list_dir/1 and file:format_error/1 (which had not been invented when the c module was first implemented). Suggested-by: Bengt Kleberg Test-suite-by: Bengt Kleberg
Diffstat (limited to 'lib/stdlib/src/c.erl')
-rw-r--r--lib/stdlib/src/c.erl6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/stdlib/src/c.erl b/lib/stdlib/src/c.erl
index 91d317489c..6e96e3d564 100644
--- a/lib/stdlib/src/c.erl
+++ b/lib/stdlib/src/c.erl
@@ -713,8 +713,10 @@ ls(Dir) ->
case file:list_dir(Dir) of
{ok, Entries} ->
ls_print(sort(Entries));
- {error,_E} ->
- format("Invalid directory\n")
+ {error, enotdir} ->
+ ls_print([Dir]);
+ {error, Error} ->
+ format("~s\n", [file:format_error(Error)])
end.
ls_print([]) -> ok;