Copies a file/dir

@param {String} from From path
@param {String} to To path
@param {Function} callback Callback
12128
function(from, to, callback) {
  fse.copy(from, to, function (err) {
    if (err) {
      callback(err);
    } else {
      callback(null);
    }
  });
}
1014085
function copyFile(source, target, copyCallback) {
    const readStream = fs.createReadStream(source);
    const writeStream = fs.createWriteStream(target);
    let done = false;

    readStream.on('error', copyDone);
    writeStream.on('error', copyDone);

    writeStream.on('close', function onWriteCb() {
        copyDone(null);
    });

    readStream.pipe(writeStream);

    /**
     * Finish copying. Reports error when needed
     * @param [error] optional error
     */
    function copyDone(error) {
        if (!done) {
            done = true;
            copyCallback(error);
        }
    }
}
1027938
public void renameFile(String from, String to) throws IOException {
    fs.rename(new Path(directory, from), new Path(directory, to));
  }
979046
function _copyFile (origin, target, callback) {

			if ("undefined" === typeof origin) {
				throw new ReferenceError("Missing \"origin\" argument");
			}
				else if ("string" !== typeof origin) {
					throw new TypeError("\"origin\" argument is not a string");
				}
				else if ("" === origin.trim()) {
					throw new TypeError("\"origin\" argument is empty");
				}
			else if ("undefined" === typeof target) {
				throw new ReferenceError("Missing \"target\" argument");
			}
				else if ("string" !== typeof target) {
					throw new TypeError("\"target\" argument is not a string");
				}
				else if ("" === target.trim()) {
					throw new Error("\"target\" argument is empty");
				}
			else if ("undefined" === typeof callback) {
				throw new ReferenceError("Missing \"callback\" argument");
			}
				else if ("function" !== typeof callback) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				isFileProm(origin).then((exists) => {
					return exists ? Promise.resolve() : Promise.reject(new Error("There is no origin file \"" + origin + "\""));
				}).then(() => {

					let error = false;

					const writeStream = createWriteStream(target).once("error", (_err) => {

						error = true;
						writeStream.close();

						callback(_err);

					}).once("close", () => {
						return error ? null : callback(null);
					});

					createReadStream(origin).once("error", (_err) => {
						error = true; callback(_err);
					}).pipe(writeStream);

				}).catch(callback);

			}

		}
752196
public static void copyDir(File from, File to) throws FileNotFoundException, IOException {
        File[] files = from.listFiles();

        if (files != null) {
            for (File ff : files) {
                File tf = new File(to, ff.getName());
                if (ff.isDirectory()) {
                    if (tf.mkdir()) {
                        copyDir(ff, tf);
                    }
                } else if (ff.isFile()) {
                    copyFile(tf, ff);
                }
            }
        }
    }
860968
function (src, target) {
  /*
   * Copy a file from one path relative to the src, to another relative to the
   * target.
   * @param {String} from - the path to copy from, relative to the src.
   * @param {String} to - the path to copy to.
   * @return {Promise} - promise to copy
   */
  this.copy = function (from, to) {
    return copy(path.resolve(src, from), path.resolve(target, to))
  }

  this.src = {
    /*
     * The source path.
     */
    path: _.clone(src),

    /*
     * Read a file, relative to the source.
     * @param {String} from - the path to read from, relative to the source.
     * @return {Promise} - a promise to return the file's content.
     */
    read: function (from) {
      return read(path.resolve(src, from))
    }

  }

  this.target = {
    /*
     * The target path.
     */
    path: _.clone(target),

    /*
     * Copy a file from one path to another, relative to the target.
     * @param {String} from - the path to copy from, relative to the target.
     * @param {String} to - the path to copy to relative to the target.
     * @return {Promise} - promise to copy
     */
    copy: function (from, to) {
      return copy(path.resolve(target, from), path.resolve(target, to))
    },

    /*
     * Read a file, relative to the target.
     * @param {String} from - the path to read from, relative to the target.
     * @return {Promise} - a promise to return the file's content.
     */
    read: function (from) {
      return read(path.resolve(target, from))
    },

    /*
     * Write a file to a path, optionally with ejs locals, relative to the
     * target.
     * @param {String} to - the path to write to, relative to the target.
     * @param {String} what - the content to write, relative to the target.
     * @param {Object} locals - object to pass as locals to ejs.
     * @return {String} - the contents of the file.
     */

    write: function (to, what, locals) {
      return write(path.resolve(target, to), what, locals)
    },

    /*
     * Rename a file, relative to the target.
     * @param {String} from - the path to the file, relative to the target.
     * @param {String} to - the new path to the file, relative to the target.
     * @return {Promise} - a promise to rename the file.
     */

    rename: function (from, to) {
      return rename(path.resolve(target, from), path.resolve(target, to))
    },

    /*
     * Remove files, relative to the target.
     * @param {String[]} what - the path(s) to read from, relative to the target.
     * @return {Promise} -  a promise to remove the file
     */
    remove: function (what) {
      return remove(target, what)
    },

    /*
     * Execute a child process at the specified working directory, relative to
     * the target.
     * @param {String} cmd - the command to run.
     * @param {string} cwd - the working directory, relative to the target
     * @return {Promise} - a promise for the standard out.
     */
    exec: function (cmd, cwd) {
      return execute(cmd, cwd ? path.resolve(target, cwd) : target)
    }
  }
}
886788
function copyDirSync(src, dest) {
  if (fs.lstatSync(src).isDirectory()) {
    const files = fs.readdirSync(src);
    files.forEach((file) => {
      const curSource = path.join(src, file);
      const curDest = path.join(dest, file);
      if (fs.lstatSync(curSource).isDirectory()) {
        if (!fs.existsSync(curDest)) {
          createDir(curDest);
        }
        copyDirSync(curSource, curDest);
      } else {
        copyFileSync(curSource, curDest);
      }
    });
  }
}
16268
private static void moveFile(final File fromFile, final File toFile) throws UpdateException {
        try {
            // Create parent directory structure if necessary
            FileUtils.mkParentDirs(toFile);
            Files.move(fromFile.toPath(), toFile.toPath(),
                    StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException ioe) {
            throw new UpdateException("Unable to move temporary file to destination file: " +
                    fromFile + " -> " + toFile + ": " + ioe.toString());
        }
    }
972449
public static function copy(string $from, string $to) {
		ref\file::path($from, true);
		if (! $from) {
			return false;
		}

		ref\file::path($to, false);
		if (! $to || ($from === $to)) {
			return false;
		}

		// Recurse directories.
		if (@\is_dir($from)) {
			ref\file::trailingslash($from);
			ref\file::trailingslash($to);

			if (! @\is_dir($to)) {
				$dir_chmod = (@\fileperms($from) & 0777 | 0755);
				if (! static::mkdir($to, $dir_chmod)) {
					return false;
				}
			}

			// Copy all files and directories within.
			if ($handle = @\opendir($from)) {
				while (false !== ($file = @\readdir($handle))) {
					// Ignore dots.
					if (('.' === $file) || ('..' === $file)) {
						continue;
					}

					// Recurse.
					static::copy("{$from}{$file}", "{$to}{$file}");
				}
				\closedir($handle);
			}

			return true;
		}
		// Let PHP handle it.
		elseif (@\is_file($from)) {
			$dir_from = \dirname($from);
			$dir_to = \dirname($to);

			// Make the TO directory if it doesn't exist.
			if (! @\is_dir($dir_to)) {
				$dir_chmod = (@\fileperms($dir_from) & 0777 | 0755);
				if (! static::mkdir($dir_to, $dir_chmod)) {
					return false;
				}
			}

			// Copy the file.
			if (! @\copy($from, $to)) {
				return false;
			}
			$file_chmod = (@\fileperms($from) & 0777 | 0644);
			@\chmod($to, $file_chmod);

			return true;
		}

		return false;
	}
79640
function copyFolder(ffs, from, to) {
    checkFolder(ffs, to);
    let tasks = [];
    ffs.readdirSync(from).forEach(child => {
        if (ffs.statSync(from + '/' + child).isDirectory()) {
            copyFolder(ffs, from + '/' + child, to + '/' + child);
        }
        else {
            copyFile(ffs, from + '/' + child, to + '/' + child);
        }
    });
}
306014
function (from, to) {
            return (new java.io.File(from)).renameTo((new java.io.File(to)));
        }
1155305
function _relativeCopy(fileGlob, from, to) {
  return glob(fileGlob, { cwd: from, nodir: true }, (err, files) => {
    if (err) throw err;
    files.forEach(file => {
      const origin = path.join(from, file);
      const dest = path.join(to, file);
      _recursiveMkDir(path.dirname(dest));
      fs.createReadStream(origin).pipe(fs.createWriteStream(dest));
    })
  })
}
482073
public static void copyFile(File from, File to) throws RuntimeIOException {
		copyFile(from, to, false);
	}
145291
public static void copy(@NotNull Path from, @NotNull Path to) throws IOException {
		Validate.notNull(from);
		Validate.notNull(to);

		if (Files.isDirectory(from)) {
			copyDir(from, to);
		} else {
			copyFile(from, to);
		}
	}
429308
function copyFile(src, dest) {
      var content = fs.readFileSync(src, 'binary');
      fs.writeFileSync(dest, content, 'binary');
    }
656188
public static void copy(File from, File to) throws IOException {
        if (from.isDirectory())
            copyDir(from, to);
        else
            copyFile(from, to);
    }
1217271
function copy(from, to) {
      var name;
      for (name in from) {
        if (from.hasOwnProperty(name)) {
          to[name] = from[name];
        }
      }
    }