Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. open Core
  2.  
  3. let archive ~src ~dst =
  4.   if not (Sys.is_directory src) then failwithf "%s: not a directory" src ();
  5.   if Sys.file_exists dst && not (Sys.is_directory dst) then begin
  6.     try Unix.unlink dst with _e -> ();
  7.   end;
  8.   try Unix.mkdir dst with _e -> ();
  9.   List.iter (Sys.ls_dir src) ~f:(fun fn ->
  10.     let srcf = src ^/ fn and dstf = dst ^/ fn in
  11.     if Sys.is_directory srcf then archive ~src:srcf ~dst:dstf
  12.     else begin
  13.       Out_channel.write_all dstf ~data:(Ezgzip.compress ~level:9 (In_channel.read_all srcf));
  14.       let st = Unix.stat srcf in
  15.       Unix.utimes dstf ~access:st.Unix.st_atime ~modif:st.Unix.st_mtime
  16.     end)
  17. ;;  
  18.  
  19. let () =
  20.   archive ~src:"/a" ~dst:"b"
  21. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement