Anonymous user
Rename a file: Difference between revisions
m
Fixed lang tags.
(→{{header|Python}}: Use OS-portable directory separator) |
m (Fixed lang tags.) |
||
Line 4:
=={{header|Ada}}==
<lang ada>with Ada.Directories; use Ada.Directories;▼
<lang ada>▼
▲with Ada.Directories; use Ada.Directories;
...
Rename ("input.txt", "output.txt");
Rename ("docs", "mydocs");
Rename ("/input.txt", "/output.txt");
Rename ("/docs", "/mydocs");</lang>
</lang>▼
The behavior depends on the concrete [[OS | operating system]] regarding:
* file name encoding issues;
Line 23 ⟶ 21:
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - ''get directory'' and'' grep in string'' not available in any library ... yet}} -->
Note: <tt>reidf</tt> does not appear to be included in [[ALGOL 68G]]. Also note that file names would be Operating System dependent.
<lang
PROC rename = (STRING source name, dest name)INT:
BEGIN
Line 49 ⟶ 46:
=={{header|AWK}}==
Awk allows to call operating system commands with the ''system()'' function. However, the awk script won't get its output, only the return code. But this task is simple enough for the trivial implementation to work:
=={{header|AutoHotkey}}==
<lang AutoHotkey>FileMove, oldname, newname</lang>
</lang>▼
=={{header|C}}==
<lang c>#include <stdio.h>
Line 73 ⟶ 68:
=={{header|C++}}==
{{trans|C}}
<lang cpp>#include <cstdio>
int main()
Line 82 ⟶ 76:
std::rename("/input.txt", "/output.txt");
std::rename("/docs", "/mydocs");
</lang>▼
=={{header|C sharp|C#}}==
Line 109 ⟶ 102:
=={{header|D}}==
<lang d>std.file.rename("input.txt","output.txt");▼
▲std.file.rename("input.txt","output.txt");
std.file.rename("/input.txt","/output.txt");
std.file.rename("docs","mydocs");
std.file.rename("/docs","/mydocs");</lang>
=={{header|DOS Batch File}}==
Line 130 ⟶ 121:
=={{header|Forth}}==
<lang forth> s" input.txt" s" output.txt" rename-file throw
=={{header|Groovy}}==
Using File
<lang groovy>['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
▲ new File("$dir/$src").renameTo(new File("$dir/$dst"))
▲}</lang>
▲ }
Using Ant
<lang groovy>['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
▲ new AntBuilder().move(file:"$dir/$src", toFile:"$dir/$dst")
▲}</lang>
▲ }
=={{header|Haskell}}==
<lang haskell>
=={{header|J}}==
Line 174 ⟶ 162:
'kernel32 MoveFileA i *c *c' 15!:0 y;x
end.
▲)</lang>
Useage:
<lang j>
=={{header|Java}}==
<lang java>
=={{header|JavaScript}}==
Line 222 ⟶ 208:
=={{header|Mathematica}}==
<lang Mathematica>
=={{header|MAXScript}}==
MAXScript has no folder rename method
=={{header|Objective-C}}==
Line 247 ⟶ 233:
=={{header|OCaml}}==
<lang ocaml>
=={{header|Pascal}}==
Line 277 ⟶ 263:
=={{header|Perl}}==
<lang perl>
=={{header|PHP}}==
Line 296 ⟶ 282:
=={{header|Pop11}}==
Note that notion of the root of filesystem is Unix specific, so above we
Line 305 ⟶ 291:
=={{header|PowerShell}}==
<lang powershell>
=={{header|Python}}==
<lang python>import os
▲ os.rename("docs", "mydocs")
▲ os.rename(os.sep + "docs", os.sep + "mydocs")
=={{header|R}}==
Line 337 ⟶ 321:
The <tt>FileUtils#move</tt> method has some more flexibility than the core <tt>File#rename</tt> method (not really demonstrated here).
<lang ruby>
=={{header|Slate}}==
<lang slate>(File newNamed: 'input.txt') renameTo: 'output.txt'.▼
▲(File newNamed: 'input.txt') renameTo: 'output.txt'.
(File newNamed: '/input.txt') renameTo: '/output.txt'.
(Directory newNamed: 'docs') renameTo: 'mydocs'.
(Directory newNamed: '/docs') renameTo: '/mydocs'.</lang>
=={{header|Smalltalk}}==
Line 358 ⟶ 340:
=={{header|Standard ML}}==
=={{header|Tcl}}==
Line 378 ⟶ 360:
=={{header|Toka}}==
<lang
=={{header|UNIX Shell}}==
<lang
=={{header|Vedit macro language}}==
Vedit allows using either '\' or '/' as directory separator character, it is automatically converted to the one used by the operating system.
<lang vedit>// In current directory
File_Rename("input.txt", "output.txt")
File_Rename("docs", "mydocs")
Line 400 ⟶ 381:
// In the root directory
File_Rename("/input.txt", "/output.txt")
File_Rename("/docs", "/mydocs")</lang>
=={{header|Visual Basic .NET}}==
Line 407 ⟶ 387:
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet>
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have a filesystem, just namespaced variables. -->
|