Why it is a illegal guard expression?

钱晓明 <>
Wed Feb 24 04:42:03 CET 2010


Hi, I am a newer of erlang. I wrote a module to find all files(no directory)
under a directory, including its subdirectory:
-module(lib_test).
-export([list_files/1]).

list_files(Path)->
    {ok, FileList} = file:list_dir(Path),
    process_filelist(FileList, []).

process_filelist([File|FileList], Files)->
    if
       filelib:is_dir(File) ->
        {ok, NewFileList} = file:list_dir(File),
        process_filelist(NewFileList, Files);
       true ->
        process_filelist(FileList, [File|Files])
    end;
process_filelist([], Files) ->
    Files.

But I fail to compile this file, because " filelib:is_dir(File) ->" is
illegal guard expression. So Why it is illegal? What should I write?
Thanks for your help!


More information about the erlang-questions mailing list