1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
|
|
|
(* General Public License. *)
|
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
open Unix
|
|
|
|
|
|
|
|
let get_files_in_directory dir =
|
1999-12-21 05:58:12 -08:00
|
|
|
match
|
|
|
|
try Some(opendir dir) with Unix_error _ -> None
|
|
|
|
with
|
|
|
|
None -> []
|
|
|
|
| Some dirh ->
|
|
|
|
let rec get_them l =
|
|
|
|
match
|
|
|
|
try Some(readdir dirh) with _ -> None
|
|
|
|
with
|
|
|
|
| Some x ->
|
|
|
|
get_them (x::l)
|
|
|
|
| None ->
|
|
|
|
closedir dirh; l
|
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
Sort.list ~order:(<=) (get_them [])
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
let is_directory name =
|
|
|
|
try
|
1999-12-10 01:40:51 -08:00
|
|
|
(stat name).st_kind = S_DIR
|
1999-11-30 06:59:39 -08:00
|
|
|
with _ -> false
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let get_directories_in_files ~path =
|
|
|
|
List.filter ~f:(fun x -> is_directory (path ^ "/" ^ x))
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(************************************************** Subshell call *)
|
2000-04-11 20:43:25 -07:00
|
|
|
let subshell ~cmd =
|
1999-11-30 06:59:39 -08:00
|
|
|
let rc = open_process_in cmd in
|
1999-12-21 05:58:12 -08:00
|
|
|
let rec it l =
|
|
|
|
match
|
|
|
|
try Some(input_line rc) with _ -> None
|
|
|
|
with
|
|
|
|
Some x -> it (x::l)
|
|
|
|
| None -> List.rev l
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
1999-12-21 05:58:12 -08:00
|
|
|
let answer = it [] in
|
1999-11-30 06:59:39 -08:00
|
|
|
ignore (close_process_in rc);
|
|
|
|
answer
|