Difference between revisions of "Rename a file or directory"

From CodeCodex

(Erlang)
(Implementations)
 
Line 56: Line 56:
 
</pre>
 
</pre>
  
 +
=== Tcl ===
 +
<pre class="tcl">
 +
file rename /path/to/old/file /path/to/new/file
 +
</pre>
 
[[Category:C]]
 
[[Category:C]]
 
[[Category:Erlang]]
 
[[Category:Erlang]]
Line 64: Line 68:
 
[[Category:Ruby]]
 
[[Category:Ruby]]
 
[[Category:Seed7]]
 
[[Category:Seed7]]
 +
[[Category:Tcl]]
 
[[Category:I/O]]
 
[[Category:I/O]]

Latest revision as of 22:06, 17 February 2011

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