gpt4 book ai didi

file - Erlang 奇怪的函数行为

转载 作者:行者123 更新时间:2023-12-01 01:31:18 25 4
gpt4 key购买 nike

我需要 erlang 中的函数,它将计算某个目录中的文件。我写了这个函数:

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

当我尝试测试它时。例如,我在 erlang shell 中运行:

1> 模块:文件计数(/home/)。

我看到异常:**异常错误:没有匹配模块的函数子句:files_count("/home/")

怎么了?

谢谢你。

最佳答案

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

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

关于file - Erlang 奇怪的函数行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4782183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com