Beispiel #1
0
  private void directory_to_directory(
      String source_base_name, String destination_base_name, String directory_name)
      throws IOException, InterruptedException {
    // E.g.
    // source_base_name:        /foo/bar
    // destination_base_name:   /x/y
    // directory_name:     abc
    //
    // - Create /x/y/abc
    // - Copy /foo/bar/abc/* to /x/y/abc/*

    // Get source directory.
    String source_directory_name = Path.concatenate(source_base_name, directory_name);
    File source_directory = File.create(source_directory_name);
    Assertion.check(source_directory.isDirectory());

    // Get destination directory, creating it if
    // necessary.
    String destination_directory_name = Path.concatenate(destination_base_name, directory_name);
    File destination_directory = File.create(destination_directory_name);
    destination_directory.mkdirs();

    // Get files in source directory
    String[] source_file_names = source_directory.list();
    Vector source_files = new Vector();
    for (int i = 0; i < source_file_names.length; i++)
      source_files.addElement(File.create(source_directory_name, source_file_names[i]));

    // Copy
    to_directory(source_files, destination_directory);
  }
Beispiel #2
0
 private void to_directory(Vector sources, File destination_directory)
     throws IOException, InterruptedException {
   Assertion.check(destination_directory.exists());
   for (Enumeration source_scan = sources.elements(); source_scan.hasMoreElements(); ) {
     File source = (File) source_scan.nextElement();
     if (source.isFile()) {
       File destination = File.create(destination_directory.getPath(), source.getName());
       file_to_file(source, destination);
     } else if (_recursive) {
       String source_base = source.getParent();
       if (source_base == null) source_base = ".";
       String destination_base = destination_directory.getCanonicalPath();
       directory_to_directory(source_base, destination_base, source.getName());
     }
   }
 }