Rename a file: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 19: Line 19:
{{trans|Python}}
{{trans|Python}}


<lang 11l>fs:rename(‘input.txt’, ‘output.txt’)
<syntaxhighlight lang="11l">fs:rename(‘input.txt’, ‘output.txt’)
fs:rename(‘docs’, ‘mydocs’)
fs:rename(‘docs’, ‘mydocs’)


fs:rename(fs:path:sep‘input.txt’, fs:path:sep‘output.txt’)
fs:rename(fs:path:sep‘input.txt’, fs:path:sep‘output.txt’)
fs:rename(fs:path:sep‘docs’, fs:path:sep‘mydocs’)</lang>
fs:rename(fs:path:sep‘docs’, fs:path:sep‘mydocs’)</syntaxhighlight>


=={{header|Action!}}==
=={{header|Action!}}==
The attached result has been obtained under DOS 2.5.
The attached result has been obtained under DOS 2.5.
{{libheader|Action! Tool Kit}}
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit
<syntaxhighlight lang="action!">INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit


PROC Dir(CHAR ARRAY filter)
PROC Dir(CHAR ARRAY filter)
Line 60: Line 60:
PrintF("Dir ""%S""%E",filter)
PrintF("Dir ""%S""%E",filter)
Dir(filter)
Dir(filter)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Rename_a_file.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Rename_a_file.png Screenshot from Atari 8-bit computer]
Line 80: Line 80:


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>with Ada.Directories; use Ada.Directories;
<syntaxhighlight lang="ada">with Ada.Directories; use Ada.Directories;
...
...
Rename ("input.txt", "output.txt");
Rename ("input.txt", "output.txt");
Rename ("docs", "mydocs");
Rename ("docs", "mydocs");
Rename ("/input.txt", "/output.txt");
Rename ("/input.txt", "/output.txt");
Rename ("/docs", "/mydocs");</lang>
Rename ("/docs", "/mydocs");</syntaxhighlight>
The behavior depends on the concrete [[OS | operating system]] regarding:
The behavior depends on the concrete [[OS | operating system]] regarding:
* file name encoding issues;
* file name encoding issues;
Line 98: Line 98:
<!-- {{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}} -->
<!-- {{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.
Note: <tt>reidf</tt> does not appear to be included in [[ALGOL 68G]]. Also note that file names would be Operating System dependent.
<lang algol68>main:(
<syntaxhighlight lang="algol68">main:(
PROC rename = (STRING source name, dest name)INT:
PROC rename = (STRING source name, dest name)INT:
BEGIN
BEGIN
Line 119: Line 119:
rename("docs", "mydocs");
rename("docs", "mydocs");
rename("/docs", "/mydocs")
rename("/docs", "/mydocs")
)</lang>
)</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>fileFrom: "input.txt"
<syntaxhighlight lang="rebol">fileFrom: "input.txt"
fileTo: "output.txt"
fileTo: "output.txt"
docsFrom: "docs"
docsFrom: "docs"
Line 134: Line 134:


rename.directory join.path ["/" docsFrom]
rename.directory join.path ["/" docsFrom]
join.path ["/" docsTo]</lang>
join.path ["/" docsTo]</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>FileMove, oldname, newname</lang>
<syntaxhighlight lang="autohotkey">FileMove, oldname, newname</syntaxhighlight>


=={{header|AutoIt}}==
=={{header|AutoIt}}==
Line 147: Line 147:
=={{header|AWK}}==
=={{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:
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:
<lang awk>$ awk 'BEGIN{system("mv input.txt output.txt")}'
<syntaxhighlight lang="awk">$ awk 'BEGIN{system("mv input.txt output.txt")}'
$ awk 'BEGIN{system("mv docs mydocs")}'
$ awk 'BEGIN{system("mv docs mydocs")}'
$ awk 'BEGIN{system("mv /input.txt /output.txt")}'
$ awk 'BEGIN{system("mv /input.txt /output.txt")}'
$ awk 'BEGIN{system("mv docs mydocs")}'</lang>
$ awk 'BEGIN{system("mv docs mydocs")}'</syntaxhighlight>


=={{header|BaCon}}==
=={{header|BaCon}}==
<lang freebasic>RENAME "input.txt" TO "output.txt"
<syntaxhighlight lang="freebasic">RENAME "input.txt" TO "output.txt"
RENAME "/input.txt" TO "/output.txt"
RENAME "/input.txt" TO "/output.txt"
RENAME "docs" TO "mydocs"
RENAME "docs" TO "mydocs"
RENAME "/docs" TO "/mydocs"
RENAME "/docs" TO "/mydocs"
</syntaxhighlight>
</lang>


=={{header|BASIC}}==
=={{header|BASIC}}==
<lang qbasic>NAME "input.txt" AS "output.txt"
<syntaxhighlight lang="qbasic">NAME "input.txt" AS "output.txt"
NAME "\input.txt" AS "\output.txt"
NAME "\input.txt" AS "\output.txt"
NAME "docs" AS "mydocs"
NAME "docs" AS "mydocs"
NAME "\docs" AS "\mydocs"</lang>
NAME "\docs" AS "\mydocs"</syntaxhighlight>


==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
Apple DOS 3.3 has a flat filesystem with no concept of directories. DOS commands such as RENAME are run directly from the Applesoft prompt but are not technically part of Applesoft BASIC. Thus, attempting to add this line to a program and run it results in a syntax error on that line.
Apple DOS 3.3 has a flat filesystem with no concept of directories. DOS commands such as RENAME are run directly from the Applesoft prompt but are not technically part of Applesoft BASIC. Thus, attempting to add this line to a program and run it results in a syntax error on that line.


<lang basic>RENAME INPUT.TXT,OUTPUT.TXT</lang>
<syntaxhighlight lang="basic">RENAME INPUT.TXT,OUTPUT.TXT</syntaxhighlight>


To use a DOS command from a program, use the BASIC statement PRINT followed by CHR$(4) and the string containing the DOS command.
To use a DOS command from a program, use the BASIC statement PRINT followed by CHR$(4) and the string containing the DOS command.


<lang basic>10 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"</lang>
<syntaxhighlight lang="basic">10 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"</syntaxhighlight>


Apple ProDOS does have directories. To change the current working directory to the "root" directory, issue a PREFIX / command.
Apple ProDOS does have directories. To change the current working directory to the "root" directory, issue a PREFIX / command.


<lang basic>10 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
<syntaxhighlight lang="basic">10 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
20 PRINT CHR$ (4)"RENAME DOCS,MYDOCS"
20 PRINT CHR$ (4)"RENAME DOCS,MYDOCS"
30 PRINT CHR$ (4)"PREFIX /"
30 PRINT CHR$ (4)"PREFIX /"
40 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
40 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
50 PRINT CHR$ (4)"RENAME DOCS,MYDOCS"</lang>
50 PRINT CHR$ (4)"RENAME DOCS,MYDOCS"</syntaxhighlight>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
'''Works with''' Commodore BASIC V2.0 as follows:
'''Works with''' Commodore BASIC V2.0 as follows:


<lang basic>OPEN 15,<Device>,15,"R<DRIVE>:FilenameOLD=FilenameNEW":CLOSE 15</lang>
<syntaxhighlight lang="basic">OPEN 15,<Device>,15,"R<DRIVE>:FilenameOLD=FilenameNEW":CLOSE 15</syntaxhighlight>


'''Works with''' Commodore BASIC 3.5 and above as follows:
'''Works with''' Commodore BASIC 3.5 and above as follows:
<lang basic>RENAME <FilenameOLD>[,D<DRIVE>] TO <FilenameNEW> [ON U<Deviceadress>]</lang>
<syntaxhighlight lang="basic">RENAME <FilenameOLD>[,D<DRIVE>] TO <FilenameNEW> [ON U<Deviceadress>]</syntaxhighlight>


==={{header|ZX Spectrum Basic}}===
==={{header|ZX Spectrum Basic}}===
Line 194: Line 194:


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>ren input.txt output.txt
<syntaxhighlight lang="dos">ren input.txt output.txt
ren \input.txt output.txt
ren \input.txt output.txt
ren docs mydocs
ren docs mydocs
ren \docs mydocs</lang>
ren \docs mydocs</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
When the file or directory names are known as constants at 'compile time':
When the file or directory names are known as constants at 'compile time':
<lang bbcbasic> *RENAME input.txt output.txt
<syntaxhighlight lang="bbcbasic"> *RENAME input.txt output.txt
*RENAME \input.txt \output.txt
*RENAME \input.txt \output.txt
*RENAME docs. mydocs.
*RENAME docs. mydocs.
*RENAME \docs. \mydocs.</lang>
*RENAME \docs. \mydocs.</syntaxhighlight>
When the file or directory names are known only at run time:
When the file or directory names are known only at run time:
<lang bbcbasic> OSCLI "RENAME input.txt output.txt"
<syntaxhighlight lang="bbcbasic"> OSCLI "RENAME input.txt output.txt"
OSCLI "RENAME \input.txt \output.txt"
OSCLI "RENAME \input.txt \output.txt"
OSCLI "RENAME docs. mydocs."
OSCLI "RENAME docs. mydocs."
OSCLI "RENAME \docs. \mydocs."</lang>
OSCLI "RENAME \docs. \mydocs."</syntaxhighlight>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat>ren$("input.txt"."output.txt") { 'ren' is based on standard C function 'rename()' }
<syntaxhighlight lang="bracmat">ren$("input.txt"."output.txt") { 'ren' is based on standard C function 'rename()' }
ren$(docs.mydocs) { No quotes needed: names don't contain dots or colons. }
ren$(docs.mydocs) { No quotes needed: names don't contain dots or colons. }
ren$("d:\\input.txt"."d:\\output.txt") { Backslash is escape character, so we need to escape it. }
ren$("d:\\input.txt"."d:\\output.txt") { Backslash is escape character, so we need to escape it. }
ren$(@"d:\docs".@"d:\mydocs") { @ used as syntactic sugar as in C# for inhibiting escape. }
ren$(@"d:\docs".@"d:\mydocs") { @ used as syntactic sugar as in C# for inhibiting escape. }
</syntaxhighlight>
</lang>


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int main()
int main()
Line 229: Line 229:
rename("/docs", "/mydocs");
rename("/docs", "/mydocs");
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp}}==
=={{header|C sharp}}==


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.IO;
using System.IO;


Line 244: Line 244:
Directory.Move(@"\docs",@"\mydocs");
Directory.Move(@"\docs",@"\mydocs");
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
{{trans|C}}
{{trans|C}}
<lang cpp>#include <cstdio>
<syntaxhighlight lang="cpp">#include <cstdio>


int main()
int main()
Line 257: Line 257:
std::rename("/docs", "/mydocs");
std::rename("/docs", "/mydocs");
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{libheader|Boost}}
{{libheader|Boost}}
Line 263: Line 263:
compiled with g++ -lboost_system -lboost_filesystem
compiled with g++ -lboost_system -lboost_filesystem


<lang cpp>#include "boost/filesystem.hpp"
<syntaxhighlight lang="cpp">#include "boost/filesystem.hpp"


int main()
int main()
Line 280: Line 280:
boost::filesystem::path("/mydocs"));*/
boost::filesystem::path("/mydocs"));*/
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|Clipper}}==
=={{header|Clipper}}==


<lang Clipper>FRename( "input.txt","output.txt")
<syntaxhighlight lang="clipper">FRename( "input.txt","output.txt")
or
or
RENAME input.txt TO output.txt
RENAME input.txt TO output.txt
Line 290: Line 290:
FRename("\input.txt","\output.txt")
FRename("\input.txt","\output.txt")
or
or
RENAME \input.txt TO \output.txt</lang>
RENAME \input.txt TO \output.txt</syntaxhighlight>


Clipper has no it's own functions to rename a directory, it is possible, though, to write appropriate code in '''C''' and link it to Clipper application, using the Clipper's Extend system.
Clipper has no it's own functions to rename a directory, it is possible, though, to write appropriate code in '''C''' and link it to Clipper application, using the Clipper's Extend system.


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(import '(java.io File))
<syntaxhighlight lang="clojure">(import '(java.io File))


(.renameTo (File. "input.txt") (File. "output.txt"))
(.renameTo (File. "input.txt") (File. "output.txt"))
Line 305: Line 305:
(.renameTo
(.renameTo
(File. (str (File/separator) "docs"))
(File. (str (File/separator) "docs"))
(File. (str (File/separator) "mydocs")))</lang>
(File. (str (File/separator) "mydocs")))</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<code>[http://www.lispworks.com/documentation/HyperSpec/Body/f_rn_fil.htm rename-file]</code>
<code>[http://www.lispworks.com/documentation/HyperSpec/Body/f_rn_fil.htm rename-file]</code>


<lang lisp>(rename-file "input.txt" "output.txt")
<syntaxhighlight lang="lisp">(rename-file "input.txt" "output.txt")
(rename-file "docs" "mydocs")
(rename-file "docs" "mydocs")
(rename-file "/input.txt" "/output.txt")
(rename-file "/input.txt" "/output.txt")
(rename-file "/docs" "/mydocs")</lang>
(rename-file "/docs" "/mydocs")</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang d>std.file.rename("input.txt","output.txt");
<syntaxhighlight 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");
std.file.rename("/docs","/mydocs");</lang>
std.file.rename("/docs","/mydocs");</syntaxhighlight>


=={{header|DBL}}==
=={{header|DBL}}==
<lang DBL>XCALL RENAM ("output.txt","input.txt")
<syntaxhighlight lang="dbl">XCALL RENAM ("output.txt","input.txt")
.IFDEF UNIX
.IFDEF UNIX
XCALL SPAWN ("mv docs mydocs")
XCALL SPAWN ("mv docs mydocs")
Line 331: Line 331:
.IFDEF VMS
.IFDEF VMS
XCALL SPAWN ("rename docs.dir mydocs.dir")
XCALL SPAWN ("rename docs.dir mydocs.dir")
.ENDC</lang>
.ENDC</syntaxhighlight>


=={{header|DCL}}==
=={{header|DCL}}==
<lang DCL>rename input.txt output.txt
<syntaxhighlight lang="dcl">rename input.txt output.txt
rename docs.dir mydocs.dir
rename docs.dir mydocs.dir
rename [000000]input.txt [000000]output.txt
rename [000000]input.txt [000000]output.txt
rename [000000]docs.dir [000000]mydocs.dir</lang>
rename [000000]docs.dir [000000]mydocs.dir</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang Delphi>program RenameFile;
<syntaxhighlight lang="delphi">program RenameFile;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 353: Line 353:
SysUtils.RenameFile('docs', 'MyDocs');
SysUtils.RenameFile('docs', 'MyDocs');
SysUtils.RenameFile('\docs', '\MyDocs');
SysUtils.RenameFile('\docs', '\MyDocs');
end.</lang>
end.</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==


<lang e>for where in [<file:.>, <file:///>] {
<syntaxhighlight lang="e">for where in [<file:.>, <file:///>] {
where["input.txt"].renameTo(where["output.txt"], null)
where["input.txt"].renameTo(where["output.txt"], null)
where["docs"].renameTo(where["mydocs"], null)
where["docs"].renameTo(where["mydocs"], null)
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>File.rename "input.txt","output.txt"
<syntaxhighlight lang="elixir">File.rename "input.txt","output.txt"
File.rename "docs", "mydocs"
File.rename "docs", "mydocs"
File.rename "/input.txt", "/output.txt"
File.rename "/input.txt", "/output.txt"
File.rename "/docs", "/mydocs"</lang>
File.rename "/docs", "/mydocs"</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<lang lisp>(rename-file "input.txt" "output.txt")
<syntaxhighlight lang="lisp">(rename-file "input.txt" "output.txt")
(rename-file "/input.txt" "/output.txt")
(rename-file "/input.txt" "/output.txt")
(rename-file "docs" "mydocs")
(rename-file "docs" "mydocs")
(rename-file "/docs" "/mydocs")</lang>
(rename-file "/docs" "/mydocs")</syntaxhighlight>


This can also be done interactively with <code>M-x rename-file</code>. Programmatically the default is to throw an error if the new name already exists but the "ok-if-already-exists" parameter can either forcibly overwrite or query the user. Query is the default interactively.
This can also be done interactively with <code>M-x rename-file</code>. Programmatically the default is to throw an error if the new name already exists but the "ok-if-already-exists" parameter can either forcibly overwrite or query the user. Query is the default interactively.
Line 378: Line 378:
=={{header|Erlang}}==
=={{header|Erlang}}==


<lang erlang>
<syntaxhighlight lang="erlang">
file:rename("input.txt","output.txt"),
file:rename("input.txt","output.txt"),
file:rename( "docs", "mydocs" ),
file:rename( "docs", "mydocs" ),
file:rename( "/input.txt", "/output.txt" ),
file:rename( "/input.txt", "/output.txt" ),
file:rename( "/docs", "/mydocs" ).
file:rename( "/docs", "/mydocs" ).
</syntaxhighlight>
</lang>


=={{header|ERRE}}==
=={{header|ERRE}}==
Line 403: Line 403:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
{{trans|C#}}
{{trans|C#}}
<lang fsharp>open System.IO
<syntaxhighlight lang="fsharp">open System.IO
[<EntryPoint>]
[<EntryPoint>]
Line 411: Line 411:
Directory.Move("docs","mydocs")
Directory.Move("docs","mydocs")
Directory.Move(@"\docs",@"\mydocs")
Directory.Move(@"\docs",@"\mydocs")
0</lang>
0</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>"" "/" [
<syntaxhighlight lang="factor">"" "/" [
[ "input.txt" "output.txt" move-file "docs" "mydocs" move-file ] with-directory
[ "input.txt" "output.txt" move-file "docs" "mydocs" move-file ] with-directory
] bi@</lang>
] bi@</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
<lang fantom>
<syntaxhighlight lang="fantom">
class Rename
class Rename
{
{
Line 432: Line 432:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Forth}}==
=={{header|Forth}}==
<lang forth> s" input.txt" s" output.txt" rename-file throw
<syntaxhighlight lang="forth"> s" input.txt" s" output.txt" rename-file throw
s" /input.txt" s" /output.txt" rename-file throw</lang>
s" /input.txt" s" /output.txt" rename-file throw</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
Using UNIX extensions to '''Fortran 77''' (see e.g. [http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Rename-Intrinsic-_0028subroutine_0029.html#Rename-Intrinsic-_0028subroutine_0029 g77 manual]) :
Using UNIX extensions to '''Fortran 77''' (see e.g. [http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Rename-Intrinsic-_0028subroutine_0029.html#Rename-Intrinsic-_0028subroutine_0029 g77 manual]) :
<lang fortran> PROGRAM EX_RENAME
<syntaxhighlight lang="fortran"> PROGRAM EX_RENAME
CALL RENAME('input.txt','output.txt')
CALL RENAME('input.txt','output.txt')
CALL RENAME('docs','mydocs')
CALL RENAME('docs','mydocs')
CALL RENAME('/input.txt','/output.txt')
CALL RENAME('/input.txt','/output.txt')
CALL RENAME('/docs','/mydocs')
CALL RENAME('/docs','/mydocs')
END</lang>
END</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


Dim result As Long
Dim result As Long
Line 461: Line 461:
End If
End If


Sleep</lang>
Sleep</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main
import "os"
import "os"


Line 472: Line 472:
os.Rename("/input.txt", "/output.txt")
os.Rename("/input.txt", "/output.txt")
os.Rename("/docs", "/mydocs")
os.Rename("/docs", "/mydocs")
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
Using File
Using File
<lang groovy>['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
<syntaxhighlight lang="groovy">['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
['.', ''].each { dir ->
['.', ''].each { dir ->
new File("$dir/$src").renameTo(new File("$dir/$dst"))
new File("$dir/$src").renameTo(new File("$dir/$dst"))
}
}
}</lang>
}</syntaxhighlight>


Using Ant
Using Ant
<lang groovy>['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
<syntaxhighlight lang="groovy">['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
['.', ''].each { dir ->
['.', ''].each { dir ->
new AntBuilder().move(file:"$dir/$src", toFile:"$dir/$dst")
new AntBuilder().move(file:"$dir/$src", toFile:"$dir/$dst")
}
}
}</lang>
}</syntaxhighlight>


=={{header|Harbour}}==
=={{header|Harbour}}==


<lang visualfoxpro>FRename( "input.txt","output.txt")
<syntaxhighlight lang="visualfoxpro">FRename( "input.txt","output.txt")
// or
// or
RENAME input.txt TO output.txt
RENAME input.txt TO output.txt


FRename( hb_ps() + "input.txt", hb_ps() + "output.txt")</lang>
FRename( hb_ps() + "input.txt", hb_ps() + "output.txt")</syntaxhighlight>


Harbour has no it's own functions to rename a directory, it is possible, though, to write appropriate code in '''C''' and link it to Harbour application, using the Harbour's Extend system.
Harbour has no it's own functions to rename a directory, it is possible, though, to write appropriate code in '''C''' and link it to Harbour application, using the Harbour's Extend system.


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import System.IO
<syntaxhighlight lang="haskell">import System.IO
import System.Directory
import System.Directory


Line 507: Line 507:
renameDirectory "docs" "mydocs"
renameDirectory "docs" "mydocs"
renameFile "/input.txt" "/output.txt"
renameFile "/input.txt" "/output.txt"
renameDirectory "/docs" "/mydocs"</lang>
renameDirectory "/docs" "/mydocs"</syntaxhighlight>


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>WRITE(FIle='input.txt', REName='.\output.txt')
<syntaxhighlight lang="hicest">WRITE(FIle='input.txt', REName='.\output.txt')
SYSTEM(DIR='E:\HicEst\Rosetta')
SYSTEM(DIR='E:\HicEst\Rosetta')
WRITE(FIle='.\docs', REName='.\mydocs')
WRITE(FIle='.\docs', REName='.\mydocs')
Line 516: Line 516:
WRITE(FIle='\input.txt', REName='\output.txt')
WRITE(FIle='\input.txt', REName='\output.txt')
SYSTEM(DIR='\')
SYSTEM(DIR='\')
WRITE(FIle='\docs', REName='\mydocs') </lang>
WRITE(FIle='\docs', REName='\mydocs') </syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Icon supports 'rename' for files only.
Icon supports 'rename' for files only.
<lang Unicon>every dir := !["./","/"] do {
<syntaxhighlight lang="unicon">every dir := !["./","/"] do {
rename(f := dir || "input.txt", dir || "output.txt") |stop("failure for file rename ",f)
rename(f := dir || "input.txt", dir || "output.txt") |stop("failure for file rename ",f)
rename(f := dir || "docs", dir || "mydocs") |stop("failure for directory rename ",f)
rename(f := dir || "docs", dir || "mydocs") |stop("failure for directory rename ",f)
}</lang>
}</syntaxhighlight>
Note: Icon and Unicon accept both / and \ for directory separators.
Note: Icon and Unicon accept both / and \ for directory separators.


=={{header|Io}}==
=={{header|Io}}==


<syntaxhighlight lang="io">
<lang Io>
// rename file in current directory
// rename file in current directory
f := File with("input.txt")
f := File with("input.txt")
Line 544: Line 544:
d := Directory with("/docs")
d := Directory with("/docs")
d moveTo("/mydocs")
d moveTo("/mydocs")
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==
Line 551: Line 551:
The following will work on Windows, Linux and Macs:
The following will work on Windows, Linux and Macs:


<lang j>frename=: 4 : 0
<syntaxhighlight lang="j">frename=: 4 : 0
if. x -: y do. return. end.
if. x -: y do. return. end.
if. IFUNIX do.
if. IFUNIX do.
Line 559: Line 559:
'kernel32 MoveFileA i *c *c' 15!:0 y;x
'kernel32 MoveFileA i *c *c' 15!:0 y;x
end.
end.
)</lang>
)</syntaxhighlight>


Useage:
Useage:
<lang j>'output.txt' frename 'input.txt'
<syntaxhighlight lang="j">'output.txt' frename 'input.txt'
'/output.txt' frename '/input.txt'
'/output.txt' frename '/input.txt'
'mydocs' frename 'docs'
'mydocs' frename 'docs'
'/mydocs' frename '/docs'</lang>
'/mydocs' frename '/docs'</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.io.File;
<syntaxhighlight lang="java">import java.io.File;
public class FileRenameTest {
public class FileRenameTest {
public static boolean renameFile(String oldname, String newname) {
public static boolean renameFile(String oldname, String newname) {
Line 593: Line 593:
test("directory", File.separator + "docs" + File.separator, File.separator + "mydocs" + File.separator);
test("directory", File.separator + "docs" + File.separator, File.separator + "mydocs" + File.separator);
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{works with|JScript}}
{{works with|JScript}}
Throws an error if the destination file/folder exists.
Throws an error if the destination file/folder exists.
<lang javascript>var fso = new ActiveXObject("Scripting.FileSystemObject")
<syntaxhighlight lang="javascript">var fso = new ActiveXObject("Scripting.FileSystemObject")
fso.MoveFile("input.txt", "output.txt")
fso.MoveFile("input.txt", "output.txt")
fso.MoveFile("c:/input.txt", "c:/output.txt")
fso.MoveFile("c:/input.txt", "c:/output.txt")
fso.MoveFolder("docs", "mydocs")
fso.MoveFolder("docs", "mydocs")
fso.MoveFolder("c:/docs", "c:/mydocs")</lang>
fso.MoveFolder("c:/docs", "c:/mydocs")</syntaxhighlight>


=={{header|Joy}}==
=={{header|Joy}}==
<syntaxhighlight lang=Joy>
<syntaxhighlight lang="joy">
"input.txt" "output.txt" frename
"input.txt" "output.txt" frename
"/input.txt" "/output.txt" frename
"/input.txt" "/output.txt" frename
Line 613: Line 613:


=={{header|Jsish}}==
=={{header|Jsish}}==
<lang javascript>/* File rename, in jsish */
<syntaxhighlight lang="javascript">/* File rename, in jsish */
try { File.rename('input.txt', 'output.txt', false); } catch (str) { puts(str); }
try { File.rename('input.txt', 'output.txt', false); } catch (str) { puts(str); }


Line 621: Line 621:


try { File.rename('docs', 'mydocs', false); } catch (str) { puts(str); }
try { File.rename('docs', 'mydocs', false); } catch (str) { puts(str); }
try { File.rename('/docs', '/mydocs', false); } catch (str) { puts(str); }</lang>
try { File.rename('/docs', '/mydocs', false); } catch (str) { puts(str); }</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>
<syntaxhighlight lang="julia">
mv("input.txt", "output.txt")
mv("input.txt", "output.txt")
mv("docs", "mydocs")
mv("docs", "mydocs")
mv("/input.txt", "/output.txt")
mv("/input.txt", "/output.txt")
mv("/docs", "/mydocs")</lang>
mv("/docs", "/mydocs")</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


/* testing on Windows 10 which needs administrative privileges
/* testing on Windows 10 which needs administrative privileges
Line 651: Line 651:
println("${oldPaths[i]} could not be renamed")
println("${oldPaths[i]} could not be renamed")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 662: Line 662:


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang Lasso >// move file
<syntaxhighlight lang="lasso ">// move file
local(f = file('input.txt'))
local(f = file('input.txt'))
#f->moveTo('output.txt')
#f->moveTo('output.txt')
Line 678: Line 678:
// move directory in root file system (requires permissions at user OS level)
// move directory in root file system (requires permissions at user OS level)
local(d = file('//docs'))
local(d = file('//docs'))
#d->moveTo('//mydocs')</lang>
#d->moveTo('//mydocs')</syntaxhighlight>


=={{header|LFE}}==
=={{header|LFE}}==


<lang lisp>
<syntaxhighlight lang="lisp">
(file:rename "input.txt" "output.txt")
(file:rename "input.txt" "output.txt")
(file:rename "docs" "mydocs")
(file:rename "docs" "mydocs")
(file:rename "/input.txt" "/output.txt")
(file:rename "/input.txt" "/output.txt")
(file:rename "/docs" "/mydocs")
(file:rename "/docs" "/mydocs")
</syntaxhighlight>
</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<lang lb>' LB has inbuilt 'name' command, but can also run batch files
<syntaxhighlight lang="lb">' LB has inbuilt 'name' command, but can also run batch files


nomainwin
nomainwin
Line 699: Line 699:
run "cmd.exe /c ren C:\docs mydocs", HIDE
run "cmd.exe /c ren C:\docs mydocs", HIDE


end</lang>
end</syntaxhighlight>


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>rename file "input.txt" to "output.txt"
<syntaxhighlight lang="livecode">rename file "input.txt" to "output.txt"
rename folder "docs" to "mydocs"
rename folder "docs" to "mydocs"
rename file "/input.txt" to "/output.txt"
rename file "/input.txt" to "/output.txt"
rename folder "/docs" to "/mydocs"</lang>
rename folder "/docs" to "/mydocs"</syntaxhighlight>


=={{header|Locomotive Basic}}==
=={{header|Locomotive Basic}}==


<lang locobasic>|ren,"input.txt","output.txt"</lang>
<syntaxhighlight lang="locobasic">|ren,"input.txt","output.txt"</syntaxhighlight>
([[wp:AMSDOS|AMSDOS]] RSX command, therefore prefixed with a vertical bar. Also, there are no subdirectories in AMSDOS, so there is no way to do the other tests.)
([[wp:AMSDOS|AMSDOS]] RSX command, therefore prefixed with a vertical bar. Also, there are no subdirectories in AMSDOS, so there is no way to do the other tests.)


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>os.rename( "input.txt", "output.txt" )
<syntaxhighlight lang="lua">os.rename( "input.txt", "output.txt" )
os.rename( "/input.txt", "/output.txt" )
os.rename( "/input.txt", "/output.txt" )
os.rename( "docs", "mydocs" )
os.rename( "docs", "mydocs" )
os.rename( "/docs", "/mydocs" )</lang>
os.rename( "/docs", "/mydocs" )</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
To delete a file we have to use Dos shell,so this can be done using Dos command
To delete a file we have to use Dos shell,so this can be done using Dos command
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module checkit {
Module checkit {
Document A$={Alfa, beta}
Document A$={Alfa, beta}
Line 731: Line 731:
}
}
checkit
checkit
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
<lang Maple>use FileTools in
<syntaxhighlight lang="maple">use FileTools in
Rename( "input.txt", "output.txt" );
Rename( "input.txt", "output.txt" );
Rename( "docs", "mydocs" );
Rename( "docs", "mydocs" );
Rename( "/input.txt", "/output.txt" ); # assuming permissions in /
Rename( "/input.txt", "/output.txt" ); # assuming permissions in /
Rename( "/docs", "/mydocs" ) # assuming permissions in /
Rename( "/docs", "/mydocs" ) # assuming permissions in /
end use:</lang>
end use:</syntaxhighlight>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>SetDirectory[NotebookDirectory[]]
<syntaxhighlight lang="mathematica">SetDirectory[NotebookDirectory[]]
RenameFile["input.txt", "output.txt"]
RenameFile["input.txt", "output.txt"]
RenameDirectory["docs", "mydocs"]
RenameDirectory["docs", "mydocs"]
SetDirectory[$RootDirectory]
SetDirectory[$RootDirectory]
RenameFile["input.txt", "output.txt"]
RenameFile["input.txt", "output.txt"]
RenameDirectory["docs", "mydocs"]</lang>
RenameDirectory["docs", "mydocs"]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==


<lang Matlab> [STATUS, MSG, MSGID] = movefile (F1, F2); </lang>
<syntaxhighlight lang="matlab"> [STATUS, MSG, MSGID] = movefile (F1, F2); </syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
MAXScript has no folder rename method
MAXScript has no folder rename method
<lang maxscript>-- Here
<syntaxhighlight lang="maxscript">-- Here
renameFile "input.txt" "output.txt"
renameFile "input.txt" "output.txt"
-- Root
-- Root
renameFile "/input.txt" "/output.txt"</lang>
renameFile "/input.txt" "/output.txt"</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang mercury>:- module rename_file.
<syntaxhighlight lang="mercury">:- module rename_file.
:- interface.
:- interface.


Line 794: Line 794:
io.write_string(Stderr, io.error_message(Error), !IO),
io.write_string(Stderr, io.error_message(Error), !IO),
io.nl(Stderr, !IO),
io.nl(Stderr, !IO),
io.set_exit_status(1, !IO).</lang>
io.set_exit_status(1, !IO).</syntaxhighlight>


=={{header|MUMPS}}==
=={{header|MUMPS}}==
<p>ANSI MUMPS doesn't allow access to the operating system except possibly through the View command and $View function, both of which are implementation specific. Intersystems' Caché does allow you to create processes with the $ZF function, and if the permissions for the Caché process allow it you can perform operating system commands.</p>
<p>ANSI MUMPS doesn't allow access to the operating system except possibly through the View command and $View function, both of which are implementation specific. Intersystems' Caché does allow you to create processes with the $ZF function, and if the permissions for the Caché process allow it you can perform operating system commands.</p>
<p>In Cache on OpenVMS in an FILES-11 filesystem ODS-5 mode these could work:</p>
<p>In Cache on OpenVMS in an FILES-11 filesystem ODS-5 mode these could work:</p>
<lang MUMPS> ;Local
<syntaxhighlight lang="mumps"> ;Local
S X=$ZF(-1,"rename input.txt output.txt")
S X=$ZF(-1,"rename input.txt output.txt")
S X=$ZF(-1,"rename docs.dir mydocs.dir")
S X=$ZF(-1,"rename docs.dir mydocs.dir")
;Root of current device
;Root of current device
S X=$ZF(-1,"rename [000000]input.txt [000000]output.txt")
S X=$ZF(-1,"rename [000000]input.txt [000000]output.txt")
S X=$ZF(-1,"rename [000000]docs.dir [000000]mydocs.dir")</lang>
S X=$ZF(-1,"rename [000000]docs.dir [000000]mydocs.dir")</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
options replace format comments java crossref symbols binary


Line 843: Line 843:


return
return
</syntaxhighlight>
</lang>


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang NewLISP>(rename-file "./input.txt" "./output.txt")
<syntaxhighlight lang="newlisp">(rename-file "./input.txt" "./output.txt")
(rename-file "./docs" "./mydocs")
(rename-file "./docs" "./mydocs")
(rename-file "/input.txt" "/output.txt")
(rename-file "/input.txt" "/output.txt")
(rename-file "/docs" "/mydocs")</lang>
(rename-file "/docs" "/mydocs")</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import os
<syntaxhighlight lang="nim">import os


moveFile("input.txt", "output.txt")
moveFile("input.txt", "output.txt")
Line 858: Line 858:


moveFile(DirSep & "input.txt", DirSep & "output.txt")
moveFile(DirSep & "input.txt", DirSep & "output.txt")
moveFile(DirSep & "docs", DirSep & "mydocs")</lang>
moveFile(DirSep & "docs", DirSep & "mydocs")</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>
<syntaxhighlight lang="objeck">
use IO;
use IO;
bundle Default {
bundle Default {
Line 873: Line 873:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
Line 880: Line 880:
{{works with|GNUstep}}
{{works with|GNUstep}}


<lang objc>NSFileManager *fm = [NSFileManager defaultManager];
<syntaxhighlight lang="objc">NSFileManager *fm = [NSFileManager defaultManager];


// Pre-OS X 10.5
// Pre-OS X 10.5
Line 888: Line 888:
// OS X 10.5+
// OS X 10.5+
[fm moveItemAtPath:@"input.txt" toPath:@"output.txt" error:NULL];
[fm moveItemAtPath:@"input.txt" toPath:@"output.txt" error:NULL];
[fm moveItemAtPath:@"docs" toPath:@"mydocs" error:NULL];</lang>
[fm moveItemAtPath:@"docs" toPath:@"mydocs" error:NULL];</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>
<syntaxhighlight lang="ocaml">
let () =
let () =
Sys.rename "input.txt" "output.txt";
Sys.rename "input.txt" "output.txt";
Sys.rename "docs" "mydocs";
Sys.rename "docs" "mydocs";
Sys.rename "/input.txt" "/output.txt";
Sys.rename "/input.txt" "/output.txt";
Sys.rename "/docs" "/mydocs";</lang>
Sys.rename "/docs" "/mydocs";</syntaxhighlight>


=={{header|Octave}}==
=={{header|Octave}}==
<lang octave>
<syntaxhighlight lang="octave">
rename('docs','mydocs');
rename('docs','mydocs');
rename('input.txt','/output.txt');
rename('input.txt','/output.txt');
rename('/docs','/mydocs');
rename('/docs','/mydocs');
</syntaxhighlight>
</lang>


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==
<lang progress>OS-RENAME "input.txt" "output.txt".
<syntaxhighlight lang="progress">OS-RENAME "input.txt" "output.txt".
OS-RENAME "docs" "mydocs".
OS-RENAME "docs" "mydocs".


OS-RENAME "/input.txt" "/output.txt".
OS-RENAME "/input.txt" "/output.txt".
OS-RENAME "/docs" "/mydocs".</lang>
OS-RENAME "/docs" "/mydocs".</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
GP has no built-in facilities for renaming, but can use a system call:
GP has no built-in facilities for renaming, but can use a system call:
<lang parigp>system("mv input.txt output.txt");
<syntaxhighlight lang="parigp">system("mv input.txt output.txt");
system("mv /input.txt /output.txt");
system("mv /input.txt /output.txt");
system("mv docs mydocs");
system("mv docs mydocs");
system("mv /docs /mydocs");</lang>
system("mv /docs /mydocs");</syntaxhighlight>
PARI, as usual, has access to all the standard [[#C|C]] methods.
PARI, as usual, has access to all the standard [[#C|C]] methods.


Alternatively it's possible to bind rename() system call to a new function:
Alternatively it's possible to bind rename() system call to a new function:
<lang parigp>install("rename","iss","rename");
<syntaxhighlight lang="parigp">install("rename","iss","rename");
rename("input.txt", "output.txt");</lang>
rename("input.txt", "output.txt");</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
<lang pascal> var
<syntaxhighlight lang="pascal"> var
f : file ; // Untyped file
f : file ; // Untyped file
begin
begin
Line 946: Line 946:
Rename(f,'\mydocs');
Rename(f,'\mydocs');
end;</lang>
end;</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use File::Copy qw(move);
<syntaxhighlight lang="perl">use File::Copy qw(move);
use File::Spec::Functions qw(catfile rootdir);
use File::Spec::Functions qw(catfile rootdir);
# here
# here
Line 956: Line 956:
# root dir
# root dir
move (catfile rootdir, 'input.txt'), (catfile rootdir, 'output.txt');
move (catfile rootdir, 'input.txt'), (catfile rootdir, 'output.txt');
move (catfile rootdir, 'docs'), (catfile rootdir, 'mydocs');</lang>
move (catfile rootdir, 'docs'), (catfile rootdir, 'mydocs');</syntaxhighlight>


The core <code>rename($oldfile,$newfile)</code> can rename a file within a directory, but has the usual limitations of the <code>rename()</code> system call or C library function, which means generally not working across filesystems, and perhaps not working to rename directories. <code>move()</code> does a copy and delete when necessary.
The core <code>rename($oldfile,$newfile)</code> can rename a file within a directory, but has the usual limitations of the <code>rename()</code> system call or C library function, which means generally not working across filesystems, and perhaps not working to rename directories. <code>move()</code> does a copy and delete when necessary.
Line 963: Line 963:
Windows now makes it fairly difficult to rename files in the root directory, even by hand.
Windows now makes it fairly difficult to rename files in the root directory, even by hand.
Output is 0 for success, 1 for failure.
Output is 0 for success, 1 for failure.
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">rename_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"input.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"output.txt"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">rename_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"input.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"output.txt"</span><span style="color: #0000FF;">)</span>
Line 969: Line 969:
<span style="color: #0000FF;">?</span><span style="color: #000000;">rename_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"C:\\Copy.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Copy.xxx"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">rename_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"C:\\Copy.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Copy.xxx"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">rename_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"C:\\docs"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"C:\\mydocs"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">rename_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"C:\\docs"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"C:\\mydocs"</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<lang Phixmonti>_platform "windows" == if "\\" "ren " else "/" "mv " endif
<syntaxhighlight lang="phixmonti">_platform "windows" == if "\\" "ren " else "/" "mv " endif
var com var slash
var com var slash


Line 978: Line 978:
com "docs mydocs" chain cmd
com "docs mydocs" chain cmd
com slash chain "input.txt " chain slash chain "output.txt" chain cmd
com slash chain "input.txt " chain slash chain "output.txt" chain cmd
com slash chain "docs " chain slash chain "mydocs" chain cmd</lang>
com slash chain "docs " chain slash chain "mydocs" chain cmd</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
<lang php><?php
<syntaxhighlight lang="php"><?php
rename('input.txt', 'output.txt');
rename('input.txt', 'output.txt');
rename('docs', 'mydocs');
rename('docs', 'mydocs');
rename('/input.txt', '/output.txt');
rename('/input.txt', '/output.txt');
rename('/docs', '/mydocs');
rename('/docs', '/mydocs');
?></lang>
?></syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(call 'mv "input.txt" "output.txt")
<syntaxhighlight lang="picolisp">(call 'mv "input.txt" "output.txt")
(call 'mv "docs" "mydocs")
(call 'mv "docs" "mydocs")
(call 'mv "/input.txt" "/output.txt")
(call 'mv "/input.txt" "/output.txt")
(call 'mv "/docs" "/mydocs")</lang>
(call 'mv "/docs" "/mydocs")</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>int main(){
<syntaxhighlight lang="pike">int main(){
mv("input.txt", "output.txt");
mv("input.txt", "output.txt");
mv("/input.txt", "/output.txt");
mv("/input.txt", "/output.txt");
mv("docs", "mydocs");
mv("docs", "mydocs");
mv("/docs", "/mydocs");
mv("/docs", "/mydocs");
}</lang>
}</syntaxhighlight>


=={{header|Pop11}}==
=={{header|Pop11}}==
<lang pop11>sys_file_move('inputs.txt', 'output.txt');
<syntaxhighlight lang="pop11">sys_file_move('inputs.txt', 'output.txt');
sys_file_move('docs', 'mydocs');
sys_file_move('docs', 'mydocs');
sys_file_move('/inputs.txt', '/output.txt');
sys_file_move('/inputs.txt', '/output.txt');
sys_file_move(/'docs', '/mydocs');</lang>
sys_file_move(/'docs', '/mydocs');</syntaxhighlight>


Note that notion of the root of filesystem is Unix specific, so above we
Note that notion of the root of filesystem is Unix specific, so above we
Line 1,012: Line 1,012:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<lang powershell>Rename-Item input.txt output.txt
<syntaxhighlight lang="powershell">Rename-Item input.txt output.txt


# The Rename-item has the alias ren
# The Rename-item has the alias ren
ren input.txt output.txt</lang>
ren input.txt output.txt</syntaxhighlight>


=={{header|Processing}}==
=={{header|Processing}}==
<lang processing>void setup(){
<syntaxhighlight lang="processing">void setup(){
boolean sketchfile = rename(sketchPath("input.txt"), sketchPath("output.txt"));
boolean sketchfile = rename(sketchPath("input.txt"), sketchPath("output.txt"));
boolean sketchfold = rename(sketchPath("docs"), sketchPath("mydocs"));
boolean sketchfold = rename(sketchPath("docs"), sketchPath("mydocs"));
Line 1,036: Line 1,036:
boolean success = file.renameTo(file2);
boolean success = file.renameTo(file2);
return success;
return success;
}</lang>
}</syntaxhighlight>


===Processing Python mode===
===Processing Python mode===
<lang python>from java.io import File
<syntaxhighlight lang="python">from java.io import File


def setup():
def setup():
Line 1,067: Line 1,067:
# Rename file (or directory)
# Rename file (or directory)
success = file.renameTo(file2)
success = file.renameTo(file2)
return success</lang>
return success</syntaxhighlight>


=={{header|ProDOS}}==
=={{header|ProDOS}}==
<lang ProDOS>rename input.txt to output.txt
<syntaxhighlight lang="prodos">rename input.txt to output.txt
rename docs to mydocs</lang>
rename docs to mydocs</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==


<lang purebasic>RenameFile("input.txt", "output.txt")
<syntaxhighlight lang="purebasic">RenameFile("input.txt", "output.txt")
RenameFile("docs\", "mydocs\")
RenameFile("docs\", "mydocs\")


RenameFile("/input.txt","/output.txt")
RenameFile("/input.txt","/output.txt")
RenameFile("/docs\","/mydocs\")</lang>
RenameFile("/docs\","/mydocs\")</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==


<lang python>import os
<syntaxhighlight lang="python">import os


os.rename("input.txt", "output.txt")
os.rename("input.txt", "output.txt")
Line 1,089: Line 1,089:


os.rename(os.sep + "input.txt", os.sep + "output.txt")
os.rename(os.sep + "input.txt", os.sep + "output.txt")
os.rename(os.sep + "docs", os.sep + "mydocs")</lang>
os.rename(os.sep + "docs", os.sep + "mydocs")</syntaxhighlight>


Or the alternative:
Or the alternative:


<lang python>import shutil
<syntaxhighlight lang="python">import shutil


shutil.move("input.txt", "output.txt")
shutil.move("input.txt", "output.txt")
Line 1,099: Line 1,099:


shutil.move("/input.txt", "/output.txt")
shutil.move("/input.txt", "/output.txt")
shutil.move("/docs", "/mydocs")</lang>
shutil.move("/docs", "/mydocs")</syntaxhighlight>


=={{header|Quackery}}==
=={{header|Quackery}}==
Line 1,105: Line 1,105:
Quackery does not have a full set of file and directory handling words, so we pass a script string to the host language. A word could be defined in Quackery to construct the appropriate script string; this is the "once-off" version.
Quackery does not have a full set of file and directory handling words, so we pass a script string to the host language. A word could be defined in Quackery to construct the appropriate script string; this is the "once-off" version.


<lang Quackery> $ "
<syntaxhighlight lang="quackery"> $ "
import os
import os
if os.path.exists('input.txt'):
if os.path.exists('input.txt'):
Line 1,127: Line 1,127:
if os.path.exists('/docs'):
if os.path.exists('/docs'):
os.rename('/docs', '/mydocs')
os.rename('/docs', '/mydocs')
" python</lang>
" python</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==


<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket


Line 1,144: Line 1,144:
(rename-file-or-directory (build-path root "docs")
(rename-file-or-directory (build-path root "docs")
(build-path root "mydocs"))
(build-path root "mydocs"))
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>rename 'input.txt', 'output.txt';
<syntaxhighlight lang="raku" line>rename 'input.txt', 'output.txt';
rename 'docs', 'mydocs';
rename 'docs', 'mydocs';
rename '/input.txt', '/output.txt';
rename '/input.txt', '/output.txt';
rename '/docs', '/mydocs';</lang>
rename '/docs', '/mydocs';</syntaxhighlight>


=={{header|Raven}}==
=={{header|Raven}}==
<lang Raven>`mv /path/to/file/oldfile /path/to/file/newfile` shell</lang>
<syntaxhighlight lang="raven">`mv /path/to/file/oldfile /path/to/file/newfile` shell</syntaxhighlight>


=={{header|REALbasic}}==
=={{header|REALbasic}}==
Line 1,160: Line 1,160:
This ''should'' work regardless of what OS it's running under (but untested under [[Mac OS]]).
This ''should'' work regardless of what OS it's running under (but untested under [[Mac OS]]).


<lang vb>Sub Renamer()
<syntaxhighlight lang="vb">Sub Renamer()
Dim f As FolderItem, r As FolderItem
Dim f As FolderItem, r As FolderItem


Line 1,188: Line 1,188:
Return what
Return what
End If
End If
End Function</lang>
End Function</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang REBOL>rename %input.txt %output.txt
<syntaxhighlight lang="rebol">rename %input.txt %output.txt
rename %docs/ %mydocs/
rename %docs/ %mydocs/


Line 1,210: Line 1,210:
rename ftp://username:password@ftp.site.com/www/input.txt %output.txt
rename ftp://username:password@ftp.site.com/www/input.txt %output.txt
rename ftp://username:password@ftp.site.com/www/docs/ %mydocs/
rename ftp://username:password@ftp.site.com/www/docs/ %mydocs/
</syntaxhighlight>
</lang>


=={{header|REXX}}==
=={{header|REXX}}==
===error messages shown===
===error messages shown===
<lang rexx>/*REXX program renames a file & a directory (in current dir & in root).*/
<syntaxhighlight lang="rexx">/*REXX program renames a file & a directory (in current dir & in root).*/
trace off /*suppress error messages, bad RC*/
trace off /*suppress error messages, bad RC*/


Line 1,222: Line 1,222:
'CD' "\" /*for 2nd pass, change──►root dir*/
'CD' "\" /*for 2nd pass, change──►root dir*/
end /*2*/
end /*2*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>


===error messages suppressed===
===error messages suppressed===
<lang rexx>/*REXX program renames a file & a directory (in current dir & in root).*/
<syntaxhighlight lang="rexx">/*REXX program renames a file & a directory (in current dir & in root).*/
trace off /*suppress error messages, bad RC*/
trace off /*suppress error messages, bad RC*/
$ = '2> NUL' /*used to suppress error messages*/
$ = '2> NUL' /*used to suppress error messages*/
Line 1,234: Line 1,234:
'CD' "\" $ /*for 2nd pass, change──►root dir*/
'CD' "\" $ /*for 2nd pass, change──►root dir*/
end /*2*/
end /*2*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
rename("input.txt", "output.txt")
rename("input.txt", "output.txt")
rename("docs", "mydocs")
rename("docs", "mydocs")
rename("/input.txt", "/output.txt")
rename("/input.txt", "/output.txt")
rename("/docs", "/mydocs")
rename("/docs", "/mydocs")
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>File.rename('input.txt', 'output.txt')
<syntaxhighlight lang="ruby">File.rename('input.txt', 'output.txt')
File.rename('/input.txt', '/output.txt')
File.rename('/input.txt', '/output.txt')
File.rename('docs', 'mydocs')
File.rename('docs', 'mydocs')
File.rename('/docs', '/mydocs')</lang>
File.rename('/docs', '/mydocs')</syntaxhighlight>


With 'fileutils' from the standard library: The <tt>FileUtils#move</tt> method has some more flexibility than the core <tt>File#rename</tt> method (not really demonstrated here).
With 'fileutils' from the standard library: The <tt>FileUtils#move</tt> method has some more flexibility than the core <tt>File#rename</tt> method (not really demonstrated here).


<lang ruby>require 'fileutils'
<syntaxhighlight lang="ruby">require 'fileutils'
moves = { "input.txt" => "output.txt", "/input.txt" => "/output.txt", "docs" => "mydocs","/docs" => "/mydocs"}
moves = { "input.txt" => "output.txt", "/input.txt" => "/output.txt", "docs" => "mydocs","/docs" => "/mydocs"}
moves.each{ |src, dest| FileUtils.move( src, dest, :verbose => true ) }</lang>
moves.each{ |src, dest| FileUtils.move( src, dest, :verbose => true ) }</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
RB has no direct command. You Shell out to windows or unix.
RB has no direct command. You Shell out to windows or unix.
<lang runbasic>a$ = shell$("RENAME input.txt output.txt")
<syntaxhighlight lang="runbasic">a$ = shell$("RENAME input.txt output.txt")
a$ = shell$("RENAME docs mydocs")
a$ = shell$("RENAME docs mydocs")
a$ = shell$("RENAME \input.txt \output.txt")
a$ = shell$("RENAME \input.txt \output.txt")
a$ = shell$("RENAME \docs \mydocs")</lang>
a$ = shell$("RENAME \docs \mydocs")</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>
<syntaxhighlight lang="rust">
use std::fs;
use std::fs;


Line 1,274: Line 1,274:
fs::rename("/docs", "/mydocs").ok().expect(err);
fs::rename("/docs", "/mydocs").ok().expect(err);
}
}
</syntaxhighlight>
</lang>


=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Scala}}
{{libheader|Scala}}
===Straight forward===
===Straight forward===
<lang Scala>import scala.language.implicitConversions
<syntaxhighlight lang="scala">import scala.language.implicitConversions
import java.io.File
import java.io.File


Line 1,290: Line 1,290:
"/tmp/mydir" renameTo "/tmp/anotherdir"
"/tmp/mydir" renameTo "/tmp/anotherdir"
}
}
}</lang>
}</syntaxhighlight>


===Alternative===
===Alternative===
<syntaxhighlight lang="scala">
<lang Scala>
object Rename1 {
object Rename1 {
def main(args: Array[String]) {
def main(args: Array[String]) {
Line 1,302: Line 1,302:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Scheme}}==
=={{header|Scheme}}==
{{works with|Chicken Scheme}}
{{works with|Chicken Scheme}}
{{works with|Guile}}
{{works with|Guile}}
<lang scheme>(rename-file "input.txt" "output.txt")
<syntaxhighlight lang="scheme">(rename-file "input.txt" "output.txt")
(rename-file "docs" "mydocs")
(rename-file "docs" "mydocs")
(rename-file "/input.txt" "/output.txt")
(rename-file "/input.txt" "/output.txt")
(rename-file "/docs" "/mydocs")</lang>
(rename-file "/docs" "/mydocs")</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==
Line 1,322: Line 1,322:
when it is started by a normal user.
when it is started by a normal user.


<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "osfiles.s7i";
include "osfiles.s7i";


Line 1,331: Line 1,331:
moveFile("/input.txt", "/output.txt");
moveFile("/input.txt", "/output.txt");
moveFile("/docs", "/mydocs");
moveFile("/docs", "/mydocs");
end func;</lang>
end func;</syntaxhighlight>


Under Windows each filesystem has its own root.
Under Windows each filesystem has its own root.
Line 1,338: Line 1,338:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby># Here
<syntaxhighlight lang="ruby"># Here
File.rename('input.txt', 'output.txt');
File.rename('input.txt', 'output.txt');
File.rename('docs', 'mydocs');
File.rename('docs', 'mydocs');
Line 1,344: Line 1,344:
# Root dir
# Root dir
File.rename(Dir.root + %f'input.txt', Dir.root + %f'output.txt');
File.rename(Dir.root + %f'input.txt', Dir.root + %f'output.txt');
File.rename(Dir.root + %f'docs', Dir.root + %f'mydocs');</lang>
File.rename(Dir.root + %f'docs', Dir.root + %f'mydocs');</syntaxhighlight>


=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>(File newNamed: 'input.txt') renameTo: 'output.txt'.
<syntaxhighlight 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'.
(Directory newNamed: '/docs') renameTo: '/mydocs'.</lang>
(Directory newNamed: '/docs') renameTo: '/mydocs'.</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
{{works with|GNU Smalltalk}}
<lang smalltalk>File rename: 'input.txt' to: 'output.txt'.
<syntaxhighlight lang="smalltalk">File rename: 'input.txt' to: 'output.txt'.
File rename: 'docs' to: 'mydocs'.
File rename: 'docs' to: 'mydocs'.
"as for other example, this works on systems
"as for other example, this works on systems
where the root is / ..."
where the root is / ..."
File rename: '/input.txt' to: '/output.txt'.
File rename: '/input.txt' to: '/output.txt'.
File rename: '/docs' to: '/mydocs'</lang>
File rename: '/docs' to: '/mydocs'</syntaxhighlight>
{{works with|Smalltalk/X}}
{{works with|Smalltalk/X}}
{{works with|VisualWorks Smalltalk}}
{{works with|VisualWorks Smalltalk}}
<lang smalltalk>'input.txt' asFilename renameTo: 'output.txt'.
<syntaxhighlight lang="smalltalk">'input.txt' asFilename renameTo: 'output.txt'.
'docs' asFilename renameTo: 'mydocs'.
'docs' asFilename renameTo: 'mydocs'.
'/input.txt' asFilename renameTo: '/output.txt'.
'/input.txt' asFilename renameTo: '/output.txt'.
'/docs' asFilename renameTo: '/mydocs'</lang>
'/docs' asFilename renameTo: '/mydocs'</syntaxhighlight>
{{works with|Pharo Smalltalk}}
{{works with|Pharo Smalltalk}}
<lang smalltalk>'input.txt' asFileReference renameTo: 'output.txt'.
<syntaxhighlight lang="smalltalk">'input.txt' asFileReference renameTo: 'output.txt'.
'docs' asFileReference renameTo: 'mydocs'.
'docs' asFileReference renameTo: 'mydocs'.
'/input.txt' asFileReference renameTo: '/output.txt'.
'/input.txt' asFileReference renameTo: '/output.txt'.
'/docs' asFileReference renameTo: '/mydocs'</lang>
'/docs' asFileReference renameTo: '/mydocs'</syntaxhighlight>


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang sml>OS.FileSys.rename {old = "input.txt", new = "output.txt"};
<syntaxhighlight lang="sml">OS.FileSys.rename {old = "input.txt", new = "output.txt"};
OS.FileSys.rename {old = "docs", new = "mydocs"};
OS.FileSys.rename {old = "docs", new = "mydocs"};
OS.FileSys.rename {old = "/input.txt", new = "/output.txt"};
OS.FileSys.rename {old = "/input.txt", new = "/output.txt"};
OS.FileSys.rename {old = "/docs", new = "/mydocs"};</lang>
OS.FileSys.rename {old = "/docs", new = "/mydocs"};</syntaxhighlight>


=={{header|Stata}}==
=={{header|Stata}}==
Use a '''[http://www.stata.com/help.cgi?shell shell]''' command. The following works on Windows, there are similar commands on other operating systems.
Use a '''[http://www.stata.com/help.cgi?shell shell]''' command. The following works on Windows, there are similar commands on other operating systems.


<lang stata>!ren input.txt output.txt
<syntaxhighlight lang="stata">!ren input.txt output.txt
!ren docs mydocs</lang>
!ren docs mydocs</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
<i>Assuming</i> that the Bash example shows what is actually meant with this task (one file and one directory here, one file and one directory in the root) and further assuming that this is supposed to be generic (i.e. OS agnostic):
<i>Assuming</i> that the Bash example shows what is actually meant with this task (one file and one directory here, one file and one directory in the root) and further assuming that this is supposed to be generic (i.e. OS agnostic):
<lang tcl>file rename inputs.txt output.txt
<syntaxhighlight lang="tcl">file rename inputs.txt output.txt
file rename docs mydocs
file rename docs mydocs
file rename [file nativename /inputs.txt] [file nativename /output.txt]
file rename [file nativename /inputs.txt] [file nativename /output.txt]
file rename [file nativename /docs] [file nativename /mydocs]</lang>
file rename [file nativename /docs] [file nativename /mydocs]</syntaxhighlight>
Without the need to work on unusual platforms like Mac OS 9, the code could be just:
Without the need to work on unusual platforms like Mac OS 9, the code could be just:
<lang tcl>file rename inputs.txt output.txt
<syntaxhighlight lang="tcl">file rename inputs.txt output.txt
file rename docs mydocs
file rename docs mydocs
file rename /inputs.txt /output.txt
file rename /inputs.txt /output.txt
file rename /docs /mydocs</lang>
file rename /docs /mydocs</syntaxhighlight>


=={{header|Toka}}==
=={{header|Toka}}==
<lang toka>needs shell
<syntaxhighlight lang="toka">needs shell
" input.txt" " output.txt" rename
" input.txt" " output.txt" rename
" /input.txt" " /output.txt" rename
" /input.txt" " /output.txt" rename


" docs" " mydocs" rename
" docs" " mydocs" rename
" /docs" " /mydocs" rename</lang>
" /docs" " /mydocs" rename</syntaxhighlight>


=={{header|TorqueScript}}==
=={{header|TorqueScript}}==
<lang Torque>fileCopy("Input.txt", "Output.txt");
<syntaxhighlight lang="torque">fileCopy("Input.txt", "Output.txt");
fileDelete("Input.txt");
fileDelete("Input.txt");


Line 1,414: Line 1,414:
fileCopy(%File, "OtherPath/" @ %File);
fileCopy(%File, "OtherPath/" @ %File);
fileDelete(%File);
fileDelete(%File);
}</lang>
}</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
$$ MODE TUSCRIPT
- rename file
- rename file
Line 1,423: Line 1,423:
- rename directory
- rename directory
ERROR/STOP RENAME ("docs","mydocs",-std-)
ERROR/STOP RENAME ("docs","mydocs",-std-)
</syntaxhighlight>
</lang>


=={{header|TXR}}==
=={{header|TXR}}==
Line 1,429: Line 1,429:
TXR works with native paths.
TXR works with native paths.


<lang txrlisp>(rename-path "input.txt" "output.txt")
<syntaxhighlight lang="txrlisp">(rename-path "input.txt" "output.txt")
;; Windows (MinGW based port)
;; Windows (MinGW based port)
(rename-path "C:\\input.txt" "C:\\output.txt")
(rename-path "C:\\input.txt" "C:\\output.txt")
;; Unix; Windows (Cygwin port)
;; Unix; Windows (Cygwin port)
(rename-path "/input.txt" "/output.txt"))</lang>
(rename-path "/input.txt" "/output.txt"))</syntaxhighlight>


Directories are renamed the same way; <code>input.txt</code> could be a directory.
Directories are renamed the same way; <code>input.txt</code> could be a directory.


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
<lang bash>mv input.txt output.txt
<syntaxhighlight lang="bash">mv input.txt output.txt
mv /input.txt /output.txt
mv /input.txt /output.txt
mv docs mydocs
mv docs mydocs
mv /docs /mydocs</lang>
mv /docs /mydocs</syntaxhighlight>


=={{header|Vedit macro language}}==
=={{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.
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
<syntaxhighlight lang="vedit">// In current directory
File_Rename("input.txt", "output.txt")
File_Rename("input.txt", "output.txt")
File_Rename("docs", "mydocs")
File_Rename("docs", "mydocs")
Line 1,451: Line 1,451:
// In the root directory
// In the root directory
File_Rename("/input.txt", "/output.txt")
File_Rename("/input.txt", "/output.txt")
File_Rename("/docs", "/mydocs")</lang>
File_Rename("/docs", "/mydocs")</syntaxhighlight>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Line 1,457: Line 1,457:


{{works with|Visual Basic .NET|9.0+}}
{{works with|Visual Basic .NET|9.0+}}
<lang vbnet>'Current Directory
<syntaxhighlight lang="vbnet">'Current Directory
IO.Directory.Move("docs", "mydocs")
IO.Directory.Move("docs", "mydocs")
IO.File.Move("input.txt", "output.txt")
IO.File.Move("input.txt", "output.txt")
Line 1,469: Line 1,469:
IO.Path.DirectorySeparatorChar & "mydocs")
IO.Path.DirectorySeparatorChar & "mydocs")
IO.File.Move(IO.Path.DirectorySeparatorChar & "input.txt", _
IO.File.Move(IO.Path.DirectorySeparatorChar & "input.txt", _
IO.Path.DirectorySeparatorChar & "output.txt")</lang>
IO.Path.DirectorySeparatorChar & "output.txt")</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-ioutil}}
{{libheader|Wren-ioutil}}
Wren-cli does not currently have the ability to rename directories, just files.
Wren-cli does not currently have the ability to rename directories, just files.
<lang ecmascript>import "/ioutil" for FileUtil
<syntaxhighlight lang="ecmascript">import "/ioutil" for FileUtil


FileUtil.move("input.txt", "output.txt")
FileUtil.move("input.txt", "output.txt")
FileUtil.move("/input.txt", "/output.txt")</lang>
FileUtil.move("/input.txt", "/output.txt")</syntaxhighlight>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>if peek$("os") = "windows" then
<syntaxhighlight lang="yabasic">if peek$("os") = "windows" then
slash$ = "\\" : com$ = "ren "
slash$ = "\\" : com$ = "ren "
else
else
Line 1,489: Line 1,489:
system(com$ + "docs mydocs")
system(com$ + "docs mydocs")
system(com$ + slash$ + "input.txt " + slash$ + "output.txt")
system(com$ + slash$ + "input.txt " + slash$ + "output.txt")
system(com$ + slash$ + "docs " + slash$ + "mydocs")</lang>
system(com$ + slash$ + "docs " + slash$ + "mydocs")</syntaxhighlight>


=={{header|Yorick}}==
=={{header|Yorick}}==
{{trans|UNIX Shell}}
{{trans|UNIX Shell}}
<lang yorick>rename, "input.txt", "output.txt";
<syntaxhighlight lang="yorick">rename, "input.txt", "output.txt";
rename, "/input.txt", "/output.txt";
rename, "/input.txt", "/output.txt";
rename, "docs", "mydocs";
rename, "docs", "mydocs";
rename, "/docs", "/mydocs";</lang>
rename, "/docs", "/mydocs";</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==