Moving a file or directory to another directory

From CodeCodex

Implementations[edit]

Java[edit]

    // This will not move files across drives.
    // File (or directory) to be moved
    File file = new File("filename");
    
    // Destination directory
    File dir = new File("directoryname");
    
    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
        // File was not successfully moved
    }

Ruby[edit]

Moves file(s) src to dest. If file and dest exist on the different disk partition, the file is copied instead.

require 'fileutils'

FileUtils.mv src, dest

Zsh[edit]

Using zmv function

autoload zmv
zmv -v file destiny

Using mv system command

mv -v file destiny