-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathio2.ml
More file actions
48 lines (44 loc) · 1.1 KB
/
io2.ml
File metadata and controls
48 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
let read_all : in_channel -> string =
fun channel ->
let contents =
really_input_string channel (in_channel_length channel)
in
close_in channel;
contents
let read_file : string -> string =
fun path ->
read_all (open_in path)
let path : string list -> string =
fun parts ->
let standard =
parts
|> List2.concat_map (String.split_on_char '/')
|> List.filter (fun s -> not (String.equal s ""))
|> String.concat "/"
in
let combined =
parts
|> String.concat ""
|> String.trim
in
if String.length combined > 0 && combined.[0] = '/' then
"/" ^ standard
else
standard
let read_path : string list -> string =
fun parts ->
parts
|> path
|> read_file
let visible_files : string -> string list =
fun dir ->
dir
|> Sys.readdir
|> Array.to_list
|> List.filter
( fun file ->
not (Sys.is_directory (path [dir; file]))
&& String.length file > 0
&& String.get file 0 <> '.'
)
|> List.sort String.compare