Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Core
- let archive ~src ~dst =
- if not (Sys.is_directory src) then failwithf "%s: not a directory" src ();
- if Sys.file_exists dst && not (Sys.is_directory dst) then begin
- try Unix.unlink dst with _e -> ();
- end;
- try Unix.mkdir dst with _e -> ();
- List.iter (Sys.ls_dir src) ~f:(fun fn ->
- let srcf = src ^/ fn and dstf = dst ^/ fn in
- if Sys.is_directory srcf then archive ~src:srcf ~dst:dstf
- else begin
- Out_channel.write_all dstf ~data:(Ezgzip.compress ~level:9 (In_channel.read_all srcf));
- let st = Unix.stat srcf in
- Unix.utimes dstf ~access:st.Unix.st_atime ~modif:st.Unix.st_mtime
- end)
- ;;
- let () =
- archive ~src:"/a" ~dst:"b"
- ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement