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 XAA21866; Sun, 21 Apr 2002 23:04:04 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 XAA21752 for ; Sun, 21 Apr 2002 23:04:03 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mel-rto4.wanadoo.fr (smtp-out-4.wanadoo.fr [193.252.19.23]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3LL42L14926 for ; Sun, 21 Apr 2002 23:04:02 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto4.wanadoo.fr; 21 Apr 2002 23:04:02 +0200 Received: from debian (80.8.81.1) by mel-rta7.wanadoo.fr (6.5.007) id 3CBAA82000270030 for caml-list@inria.fr; Sun, 21 Apr 2002 23:04:02 +0200 Received: from moi by debian with local (Exim 3.35 #1 (Debian)) id 16zOVE-0000Xz-00 for ; Sun, 21 Apr 2002 23:04:08 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Unix-Filekind => codexample with questions References: From: Remi VANICAT Date: 21 Apr 2002 23:04:08 +0200 In-Reply-To: Message-ID: <87662kdarb.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oliver Bandel writes: > Hello, > > I need a function, which tells me if a file is > a regular file or not. > > 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;; > > > [...] > > IMHO it looks a littlebid dirty, to return Unix.S_DIR > on an error-case, even if it is only internal to the > function is_regularfile. it is, i would use : let is_regularfile name = let filekind name = let tmp = Unix.stat name in tmp.Unix.st_kind in try match filekind name with | Unix.S_REG -> true | _ -> false;; with | Unix.Unix_error (Unix.ENOENT,_,_) -> false | _ -> false -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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