Rename a file: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 57: Line 57:
rename("/docs", "/mydocs")
rename("/docs", "/mydocs")
)</lang>
)</lang>

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


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
Line 73: Line 66:
DirMove("docs", "mydocs")
DirMove("docs", "mydocs")
DirMove("\docs", "\mydocs")
DirMove("\docs", "\mydocs")

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


=={{header|BaCon}}==
=={{header|BaCon}}==
Line 151: Line 151:
rename("/docs", "/mydocs");
rename("/docs", "/mydocs");
return 0;
return 0;
}</lang>

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

<lang csharp>using System;
using System.IO;

class Program {
static void Main(string[] args) {
File.Move("input.txt","output.txt");
File.Move(@"\input.txt",@"\output.txt");

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


Line 187: Line 202:
boost::filesystem::path("/mydocs"));*/
boost::filesystem::path("/mydocs"));*/
return 0;
return 0;
}</lang>

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

<lang csharp>using System;
using System.IO;

class Program {
static void Main(string[] args) {
File.Move("input.txt","output.txt");
File.Move(@"\input.txt",@"\output.txt");

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


Line 869: Line 869:


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.

=={{header|Perl 6}}==
<lang perl6>rename 'input.txt', 'output.txt';
rename 'docs', 'mydocs';
rename '/input.txt', '/output.txt';
rename '/docs', '/mydocs';</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,005: Line 999:
(build-path root "mydocs"))
(build-path root "mydocs"))
</lang>
</lang>

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


=={{header|Raven}}==
=={{header|Raven}}==
Line 1,323: Line 1,324:
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")</lang>

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


=={{header|Yabasic}}==
=={{header|Yabasic}}==
Line 1,342: Line 1,336:
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")</lang>

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


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