2011-01-24 13 views
4

何かのディレクトリにあるファイルをカウントするerlangの関数が必要です。私はこの関数を書いています:Erlangの不思議な関数の振る舞い

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

私はそれをテストしようとします。私はerlangシェルで実行します:

1> module:files_count(/ home /)

I参照exceptrion:**例外エラー:機能なし句マッチングモジュール:files_count( "/ホーム/")

何が悪いのでしょうか?

ありがとうございます。

答えて

4
-module(countfiles). 
-export([files_count/1]). 

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

はい、ありがとうございます。原子の問題が発生しました:))) – 0xAX

+0

@shk:はい、変数は大文字で始まり、小文字で始まります。 –

関連する問題