summaryrefslogtreecommitdiff
path: root/ols/ols.ml
diff options
context:
space:
mode:
authordianshi <dianshi@main.lv>2020-07-10 22:37:02 +0100
committerdianshi <dianshi@main.lv>2020-07-10 22:37:02 +0100
commit0aeabc5237e0046f6c9c186a87f9e00484f9643a (patch)
tree114610a5cadb8481ca97eecdef32c322f1533946 /ols/ols.ml
parent2e81ecf46d44b91bcdef35ef3e900554f3cb187c (diff)
downloadosystem-0aeabc5237e0046f6c9c186a87f9e00484f9643a.tar.gz
osystem-0aeabc5237e0046f6c9c186a87f9e00484f9643a.zip
Create recrusive print list function
Diffstat (limited to 'ols/ols.ml')
-rw-r--r--ols/ols.ml21
1 files changed, 18 insertions, 3 deletions
diff --git a/ols/ols.ml b/ols/ols.ml
index 96f9847..5e53bc7 100644
--- a/ols/ols.ml
+++ b/ols/ols.ml
@@ -3,23 +3,38 @@ open Unix
open Scanf
open Printf
+
+let files = ref [];;
+
let main dir =
let _ = Printf.printf "list directory %s" dir in
+ (*let files = ref [""] in*)
let dirfd = opendir dir in
try
while true do
let fname = readdir dirfd in
- Printf.printf "%s\n" fname
- done
+ let _ = (Printf.printf "%s\n" fname) in
+ files := List.append !files [fname]
+ done
with End_of_file -> closedir dirfd
+let rec print_list lst =
+ match lst with
+ | [] -> []
+ | hd::tl ->
+ let _ = Printf.printf "%s\n" hd in
+ print_list tl
let num = Array.length Sys.argv
let _ = if num == 2 then
begin
(*Printf.printf "%s\n" Sys.argv.(1) *)
- main Sys.argv.(1)
+ let _ = main Sys.argv.(1) in
+ let _ = print_list !files in
+ Printf.printf "\n"
end
else
+ begin
main "."
+ end