1 (*************************************************************************)
3 (* Objective Caml LablTk library *)
5 (* Jacques Garrigue, Kyoto University RIMS *)
7 (* Copyright 1999 Institut National de Recherche en Informatique et *)
8 (* en Automatique and Kyoto University. All rights reserved. *)
9 (* This file is distributed under the terms of the GNU Library *)
10 (* General Public License, with the special exception on linking *)
11 (* described in file ../../../LICENSE. *)
13 (*************************************************************************)
15 (* $Id: useunix.ml 5094 2002-08-09 10:34:44Z garrigue $ *)
20 let get_files_in_directory dir =
21 let len = String.length dir in
23 if len > 0 && Sys.os_type = "Win32" &&
24 (dir.[len-1] = '/' || dir.[len-1] = '\\')
25 then String.sub dir ~pos:0 ~len:(len-1)
28 try Some(opendir dir) with Unix_error _ -> None
34 try Some(readdir dirh) with _ -> None
41 List.sort ~cmp:compare (get_them [])
43 let is_directory name =
45 (stat name).st_kind = S_DIR
49 let len = String.length dir in
50 if len = 0 then name else
51 if dir.[len-1] = '/' then dir ^ name
54 let get_directories_in_files ~path =
55 List.filter ~f:(fun x -> is_directory (concat path x))
57 (************************************************** Subshell call *)
59 let rc = open_process_in cmd in
62 try Some(input_line rc) with _ -> None
68 ignore (close_process_in rc);