Commit 7a410834 authored by Idir Lankri's avatar Idir Lankri

Add module Dir for operations on directories

parent 8c3af172
......@@ -49,6 +49,9 @@ skt_lexer.cmo : encode.cmo
skt_lexer.cmx : encode.cmx
test_stamp.cmo : version.cmo paths.cmo ../ZEN/gen.cmo control.cmo
test_stamp.cmx : version.cmx paths.cmx ../ZEN/gen.cmx control.cmx
dir.cmi :
dir.cmo : dir.cmi
dir.cmx : dir.cmi
paths.cmo :
paths.cmx :
index.cmo : web.cmo ../ZEN/trie.cmo ../ZEN/list2.cmo ../ZEN/gen.cmo \
......
......@@ -33,8 +33,9 @@ VPATH=$(ZEN)
# CORE package - utilities, transducers, sanskrit and french lexers, dico spec
CORE=$(DISTR_CORE) paths.ml
DISTR_CORE= control.ml version.ml date.ml canon.ml transduction.ml encode.ml \
order.ml padapatha.ml sanskrit.mli sanskrit.ml skt_lexer.ml test_stamp.ml
DISTR_CORE = control.ml version.ml date.ml canon.ml transduction.ml \
encode.ml order.ml padapatha.ml sanskrit.mli \
sanskrit.ml skt_lexer.ml test_stamp.ml dir.mli dir.ml
# GRAM package - phonetics, morphology, segmentation and tagging engines
GRAM=index.ml phonetics.ml int_sandhi.ml skt_morph.mli morphology.mli naming.ml \
......
(*i module Dir = struct i*)
(* Return the list of files in the given directory with their absolute
name. *)
value abs_files dir =
let files = Array.to_list (Sys.readdir dir) in
List.map (Filename.concat dir) files
;
value basenames files = List.map Filename.basename files
;
value subdirs dir =
let subdirs = List.filter Sys.is_directory (abs_files dir) in
List.sort String.compare (basenames subdirs)
;
value file_with_ext ext file =
not (Sys.is_directory file) && Filename.check_suffix file ("." ^ ext)
;
value files_with_ext ext dirname =
let files = List.filter (file_with_ext ext) (abs_files dirname) in
basenames files
;
(*i end; i*)
(* Directory operations. *)
(*i module Dir : sig i*)
(* [subdirs dirname] returns the list of subdirectories of [dirname].
This list is sorted alphabetically. *)
value subdirs : string -> list string
;
(* [files_with_ext ext dirname] returns the list of files in [dirname]
with the extension [ext]. This list is sorted alphabetically. *)
value files_with_ext : string -> string -> list string
;
(*i end; i*)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment