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 *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* General Public License, with the special exception on linking *)
|
|
|
|
(* described in file ../../../LICENSE. *)
|
1999-12-16 04:25:11 -08:00
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
2001-09-06 01:52:32 -07:00
|
|
|
open StdLabels
|
|
|
|
open UnixLabels
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
let get_files_in_directory dir =
|
2002-08-09 03:34:44 -07:00
|
|
|
let len = String.length dir in
|
|
|
|
let dir =
|
|
|
|
if len > 0 && Sys.os_type = "Win32" &&
|
|
|
|
(dir.[len-1] = '/' || dir.[len-1] = '\\')
|
|
|
|
then String.sub dir ~pos:0 ~len:(len-1)
|
|
|
|
else dir
|
|
|
|
in match
|
1999-12-21 05:58:12 -08:00
|
|
|
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
|
2001-09-06 01:52:32 -07:00
|
|
|
List.sort ~cmp:compare (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
|
|
|
|
|
2002-08-09 03:34:44 -07:00
|
|
|
let concat dir name =
|
|
|
|
let len = String.length dir in
|
|
|
|
if len = 0 then name else
|
|
|
|
if dir.[len-1] = '/' then dir ^ name
|
|
|
|
else dir ^ "/" ^ name
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let get_directories_in_files ~path =
|
2002-08-09 03:34:44 -07:00
|
|
|
List.filter ~f:(fun x -> is_directory (concat 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
|