let oc = open_out filename in
output_string oc text;
close_out oc
+
+let find ?(test = fun _ -> true) path =
+ let rec aux acc todo =
+ match todo with
+ | [] -> acc
+ | path :: tl ->
+ try
+ let handle = Unix.opendir path in
+ let dirs = ref [] in
+ let matching_files = ref [] in
+ (try
+ while true do
+ match Unix.readdir handle with
+ | "." | ".." -> ()
+ | entry ->
+ let qentry = path ^ "/" ^ entry in
+ (try
+ if is_dir qentry then
+ dirs := qentry :: !dirs
+ else if test qentry then
+ matching_files := qentry :: !matching_files;
+ with Unix.Unix_error _ -> ())
+ done
+ with End_of_file -> Unix.closedir handle);
+ aux (!matching_files @ acc) (!dirs @ tl)
+ with Unix.Unix_error _ -> aux acc tl
+ in
+ aux [] [path]
(** {2 Exception handling} *)
val is_regular: string -> bool (** @return true if file is a regular file *)
val mkdir: string -> unit (** create dir and parents. @raise Failure *)
+ (** find all _files_ matching test under a filesystem root *)
+val find: ?test:(string -> bool) -> string -> string list
+
(** {2 File I/O} *)
val input_file: string -> string (** read all the contents of file to string *)