From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA21909; Sun, 21 Apr 2002 23:33:06 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA22304 for caml-list@pauillac.inria.fr; Sun, 21 Apr 2002 23:33:06 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA22041 for ; Sun, 21 Apr 2002 23:12:58 +0200 (MET DST) Received: from laurelin.dementia.org ([208.167.88.73]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3LLCuL15313 for ; Sun, 21 Apr 2002 23:12:57 +0200 (MET DST) Received: (from jprevost@localhost) by laurelin.dementia.org (8.11.6/8.11.6) id g3LLHh346765; Sun, 21 Apr 2002 17:17:43 -0400 (EDT) (envelope-from visigoth@cs.cmu.edu) X-Authentication-Warning: laurelin.dementia.org: jprevost set sender to visigoth@cs.cmu.edu using -f To: Oliver Bandel Cc: caml-list@inria.fr Subject: Re: [Caml-list] Unix-Filekind => codexample with questions References: From: John Prevost Date: 21 Apr 2002 17:17:32 -0400 In-Reply-To: Message-ID: <86u1q421lf.fsf@laurelin.dementia.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "ob" == Oliver Bandel writes: ob> Hello, I need a function, which tells me if a file is a ob> regular file or not. ob> Please look at my code-example: let is_regularfile name = let filekind name = let tmp = Unix.stat name in tmp.Unix.st_kind in let fk = try (filekind name ) with | Unix.Unix_error (Unix.ENOENT,_,_) -> Unix.S_DIR | _ -> Unix.S_DIR in match fk with | Unix.S_REG -> true | _ -> false;; ob> This example works: It tells me, if a file is of kind/type ob> regular file with true. If it is not a regular file or an ob> error occured, it tells me this by passing me the result ob> false. How about: let is_regularfile name = try (match Unix.stat name with | {Unix.st_kind = Unix.S_REG} -> true | _ -> false) with _ -> false I'm not sure why you're using so many intermediate values here--it just seems to make the code harder to figure out. Better to just wrap a try around the whole check, and use a small simple match on the stat result. John. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners