Rename a file or directory

From CodeCodex

Implementations[edit]

C[edit]

#include <stdio.h>
rename("/path/to/old/file", "/path/to/new/file");

Erlang[edit]

file:rename("/path/to/old/file", "/path/to/new/file").

Java[edit]

    // File (or directory) with old name
    File file = new File("oldname");
    
    // File (or directory) with new name
    File file2 = new File("newname");
    
    // Rename file (or directory)
    boolean success = file.renameTo(file2);
    if (!success) {
        // File was not successfully renamed
    }

OCaml[edit]

Sys.rename "/path/to/old/file" "/path/to/new/file"

Perl[edit]

rename("/path/to/old/file", "/path/to/new/file");

Python[edit]

os.rename("/path/to/old/file", "/path/to/new/file")

Ruby[edit]

begin
  File.rename("/path/to/old/file", "/path/to/new/file")
rescue Exception => e
  # handle file rename error here
end

Seed7[edit]

moveFile("/path/to/old/file", "/path/to/new/file");

Tcl[edit]

file rename /path/to/old/file /path/to/new/file