let copy_files srcs dst_dir =
  if not (is_directory dst_dir)
  then
    failwith (Printf.sprintf "Filew.copy_files: not a directory: %S" dst_dir)
  else
    (let copied_files = ref []
     in
       try
         List.iter
           (fun path ->
              let new_path =
                Filename.concat dst_dir (Filename.basename path) in
              let () = copy_file path new_path
              in copied_files := new_path :: !copied_files)
           srcs
       with | e -> (List.iter remove_file !copied_files; raise e))