Goals
The goal with this very simple script
is to list a directory and find who is a directory, who is a file.
The secondary goal (for me) is to run
it as a script. I dont want to compile it but just run it as I would
run bash, Perl or PHP script.
The code
This is how I do it :#!/usr/bin/ocamlrun /usr/bin/ocaml #load "unix.cma";; print_string "Loaded Unix\n";; let tmp_dir = Unix.opendir "/tmp";; print_string "opened /tmp\n";; (* let tmp_dir_files = Unix.readdir tmp_dir;; *) let print_type a_thing = match Sys.is_directory ("/tmp/" ^ a_thing) with | true -> print_string ("Dir:\t" ^ a_thing ^ "/\n") | false -> print_string ("File:\t" ^ a_thing ^ "\n");; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_type (Unix.readdir tmp_dir);; print_string "Listed files in /tmp\n";;