Erlang weird function behavior

I need a function in erlang that will read files in something directory. I am writing this function:

files_count(dir) -> case file:list_dir(dir) of {ok, FileNames} -> length(FileNames); {error, Reason} -> Reason end. 

When I try to test it. For example, I run the erlang shell:

1> module: files_count (/ home /).

I see exceptrion: ** exception error: no function matching module: files_count ("/ home /")

What's wrong?

Thanks.

+4
source share
1 answer
 -module(countfiles). -export([files_count/1]). files_count(Dir) -> case file:list_dir(Dir) of {ok, FileNames} -> length(FileNames); {error, Reason} -> Reason end. 
+4
source

Source: https://habr.com/ru/post/1336785/


All Articles