--- src/filelib.erl.orig	Tue Sep 16 15:23:05 2003
+++ src/filelib.erl	Tue Sep 16 15:30:19 2003
@@ -67,8 +67,8 @@
 
 fold_files([File|T], Dir, RegExp, Recursive, Fun, Acc0) ->
     FullName = Dir ++  [$/|File],
-    case is_file(FullName) of
-	true  ->
+    case {is_dir(FullName), Recursive} of
+	{false, _} ->
 	    case regexp:match(FullName, RegExp) of
 		{match, _, _}  -> 
 		    Acc = Fun(FullName, Acc0),
@@ -76,15 +76,14 @@
 		_ ->
 		    fold_files(T, Dir, RegExp, Recursive, Fun, Acc0)
 	    end;
-	false ->
-	    case Recursive and is_dir(FullName) of
-		true ->
-		    Acc1 = fold_files1(FullName, RegExp, Recursive, Fun, Acc0),
-		    fold_files(T, Dir, RegExp, Recursive, Fun, Acc1);
-		false ->
-		    fold_files(T, Dir, RegExp, Recursive, Fun, Acc0)
-	    end
-    end.
+	{true, false} ->
+	    fold_files(T, Dir, RegExp, Recursive, Fun, Acc0);
+	{true, true} ->
+	    Acc1 = fold_files1(FullName, RegExp, Recursive, Fun, Acc0),
+	    fold_files(T, Dir, RegExp, Recursive, Fun, Acc1)
+    end;
+fold_files([], Dir, RegExp, Recursive, Fun, Acc0) ->
+    Acc0.
 
 last_modified(File) ->
     case file:read_file_info(File) of
