Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Rename-a-file/00-META.yaml
Normal file
3
Task/Rename-a-file/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Rename_a_file
|
||||
note: File System Operations
|
||||
15
Task/Rename-a-file/00-TASK.txt
Normal file
15
Task/Rename-a-file/00-TASK.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;Task:
|
||||
Rename:
|
||||
:::* a file called '''input.txt''' into '''output.txt''' and
|
||||
:::* a directory called '''docs''' into '''mydocs'''.
|
||||
|
||||
|
||||
This should be done twice:
|
||||
once "here", i.e. in the current working directory and once in the filesystem root.
|
||||
|
||||
It can be assumed that the user has the rights to do so.
|
||||
|
||||
(In unix-type systems, only the user root would have
|
||||
sufficient permissions in the filesystem root.)
|
||||
<br><br>
|
||||
|
||||
5
Task/Rename-a-file/11l/rename-a-file.11l
Normal file
5
Task/Rename-a-file/11l/rename-a-file.11l
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fs:rename(‘input.txt’, ‘output.txt’)
|
||||
fs:rename(‘docs’, ‘mydocs’)
|
||||
|
||||
fs:rename(fs:path:sep‘input.txt’, fs:path:sep‘output.txt’)
|
||||
fs:rename(fs:path:sep‘docs’, fs:path:sep‘mydocs’)
|
||||
22
Task/Rename-a-file/ALGOL-68/rename-a-file.alg
Normal file
22
Task/Rename-a-file/ALGOL-68/rename-a-file.alg
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
main:(
|
||||
PROC rename = (STRING source name, dest name)INT:
|
||||
BEGIN
|
||||
FILE actual file;
|
||||
INT errno = open(actual file, source name, stand back channel);
|
||||
IF errno NE 0 THEN
|
||||
errno
|
||||
ELSE
|
||||
IF reidf possible(actual file) THEN
|
||||
reidf(actual file, dest name); # change the identification of the book #
|
||||
errno
|
||||
ELSE
|
||||
close(actual file);
|
||||
-1
|
||||
FI
|
||||
FI
|
||||
END;
|
||||
rename("input.txt", "output.txt");
|
||||
rename("/input.txt", "/output.txt");
|
||||
rename("docs", "mydocs");
|
||||
rename("/docs", "/mydocs")
|
||||
)
|
||||
4
Task/Rename-a-file/AWK/rename-a-file.awk
Normal file
4
Task/Rename-a-file/AWK/rename-a-file.awk
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
$ 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")}'
|
||||
33
Task/Rename-a-file/Action-/rename-a-file.action
Normal file
33
Task/Rename-a-file/Action-/rename-a-file.action
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit
|
||||
|
||||
PROC Dir(CHAR ARRAY filter)
|
||||
BYTE dev=[1]
|
||||
CHAR ARRAY line(255)
|
||||
|
||||
Close(dev)
|
||||
Open(dev,filter,6)
|
||||
DO
|
||||
InputSD(dev,line)
|
||||
PrintE(line)
|
||||
IF line(0)=0 THEN
|
||||
EXIT
|
||||
FI
|
||||
OD
|
||||
Close(dev)
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
CHAR ARRAY filter="D:*.*",
|
||||
cmd="D:INPUT.TXT OUTPUT.TXT"
|
||||
|
||||
Put(125) PutE() ;clear screen
|
||||
|
||||
PrintF("Dir ""%S""%E",filter)
|
||||
Dir(filter)
|
||||
|
||||
PrintF("Rename ""%S""%E%E",cmd)
|
||||
Rename(cmd)
|
||||
|
||||
PrintF("Dir ""%S""%E",filter)
|
||||
Dir(filter)
|
||||
RETURN
|
||||
6
Task/Rename-a-file/Ada/rename-a-file.ada
Normal file
6
Task/Rename-a-file/Ada/rename-a-file.ada
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
with Ada.Directories; use Ada.Directories;
|
||||
...
|
||||
Rename ("input.txt", "output.txt");
|
||||
Rename ("docs", "mydocs");
|
||||
Rename ("/input.txt", "/output.txt");
|
||||
Rename ("/docs", "/mydocs");
|
||||
1
Task/Rename-a-file/Applesoft-BASIC/rename-a-file-1.basic
Normal file
1
Task/Rename-a-file/Applesoft-BASIC/rename-a-file-1.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
RENAME INPUT.TXT,OUTPUT.TXT
|
||||
1
Task/Rename-a-file/Applesoft-BASIC/rename-a-file-2.basic
Normal file
1
Task/Rename-a-file/Applesoft-BASIC/rename-a-file-2.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
10 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
|
||||
5
Task/Rename-a-file/Applesoft-BASIC/rename-a-file-3.basic
Normal file
5
Task/Rename-a-file/Applesoft-BASIC/rename-a-file-3.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
10 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
|
||||
20 PRINT CHR$ (4)"RENAME DOCS,MYDOCS"
|
||||
30 PRINT CHR$ (4)"PREFIX /"
|
||||
40 PRINT CHR$ (4)"RENAME INPUT.TXT,OUTPUT.TXT"
|
||||
50 PRINT CHR$ (4)"RENAME DOCS,MYDOCS"
|
||||
13
Task/Rename-a-file/Arturo/rename-a-file.arturo
Normal file
13
Task/Rename-a-file/Arturo/rename-a-file.arturo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
fileFrom: "input.txt"
|
||||
fileTo: "output.txt"
|
||||
docsFrom: "docs"
|
||||
docsTo: "mydocs"
|
||||
|
||||
rename fileFrom fileTo
|
||||
rename.directory docsFrom docsTo
|
||||
|
||||
rename join.path ["/" fileFrom]
|
||||
join.path ["/" fileTo]
|
||||
|
||||
rename.directory join.path ["/" docsFrom]
|
||||
join.path ["/" docsTo]
|
||||
1
Task/Rename-a-file/AutoHotkey/rename-a-file.ahk
Normal file
1
Task/Rename-a-file/AutoHotkey/rename-a-file.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
FileMove, oldname, newname
|
||||
4
Task/Rename-a-file/BASIC/rename-a-file.basic
Normal file
4
Task/Rename-a-file/BASIC/rename-a-file.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
NAME "input.txt" AS "output.txt"
|
||||
NAME "\input.txt" AS "\output.txt"
|
||||
NAME "docs" AS "mydocs"
|
||||
NAME "\docs" AS "\mydocs"
|
||||
4
Task/Rename-a-file/BBC-BASIC/rename-a-file-1.basic
Normal file
4
Task/Rename-a-file/BBC-BASIC/rename-a-file-1.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
*RENAME input.txt output.txt
|
||||
*RENAME \input.txt \output.txt
|
||||
*RENAME docs. mydocs.
|
||||
*RENAME \docs. \mydocs.
|
||||
4
Task/Rename-a-file/BBC-BASIC/rename-a-file-2.basic
Normal file
4
Task/Rename-a-file/BBC-BASIC/rename-a-file-2.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
OSCLI "RENAME input.txt output.txt"
|
||||
OSCLI "RENAME \input.txt \output.txt"
|
||||
OSCLI "RENAME docs. mydocs."
|
||||
OSCLI "RENAME \docs. \mydocs."
|
||||
4
Task/Rename-a-file/BaCon/rename-a-file.bacon
Normal file
4
Task/Rename-a-file/BaCon/rename-a-file.bacon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
RENAME "input.txt" TO "output.txt"
|
||||
RENAME "/input.txt" TO "/output.txt"
|
||||
RENAME "docs" TO "mydocs"
|
||||
RENAME "/docs" TO "/mydocs"
|
||||
4
Task/Rename-a-file/Batch-File/rename-a-file.bat
Normal file
4
Task/Rename-a-file/Batch-File/rename-a-file.bat
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ren input.txt output.txt
|
||||
ren \input.txt output.txt
|
||||
ren docs mydocs
|
||||
ren \docs mydocs
|
||||
4
Task/Rename-a-file/Bracmat/rename-a-file.bracmat
Normal file
4
Task/Rename-a-file/Bracmat/rename-a-file.bracmat
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
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$("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. }
|
||||
10
Task/Rename-a-file/C++/rename-a-file-1.cpp
Normal file
10
Task/Rename-a-file/C++/rename-a-file-1.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <cstdio>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::rename("input.txt", "output.txt");
|
||||
std::rename("docs", "mydocs");
|
||||
std::rename("/input.txt", "/output.txt");
|
||||
std::rename("/docs", "/mydocs");
|
||||
return 0;
|
||||
}
|
||||
18
Task/Rename-a-file/C++/rename-a-file-2.cpp
Normal file
18
Task/Rename-a-file/C++/rename-a-file-2.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "boost/filesystem.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::filesystem::rename(
|
||||
boost::filesystem::path("input.txt"),
|
||||
boost::filesystem::path("output.txt"));
|
||||
boost::filesystem::rename(
|
||||
boost::filesystem::path("docs"),
|
||||
boost::filesystem::path("mydocs"));
|
||||
boost::filesystem::rename(
|
||||
boost::filesystem::path("/input.txt"),
|
||||
boost::filesystem::path("/output.txt"));
|
||||
boost::filesystem::rename(
|
||||
boost::filesystem::path("/docs"),
|
||||
boost::filesystem::path("/mydocs"));*/
|
||||
return 0;
|
||||
}
|
||||
12
Task/Rename-a-file/C-sharp/rename-a-file.cs
Normal file
12
Task/Rename-a-file/C-sharp/rename-a-file.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
10
Task/Rename-a-file/C/rename-a-file.c
Normal file
10
Task/Rename-a-file/C/rename-a-file.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
rename("input.txt", "output.txt");
|
||||
rename("docs", "mydocs");
|
||||
rename("/input.txt", "/output.txt");
|
||||
rename("/docs", "/mydocs");
|
||||
return 0;
|
||||
}
|
||||
7
Task/Rename-a-file/Clipper/rename-a-file.clipper
Normal file
7
Task/Rename-a-file/Clipper/rename-a-file.clipper
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
FRename( "input.txt","output.txt")
|
||||
or
|
||||
RENAME input.txt TO output.txt
|
||||
|
||||
FRename("\input.txt","\output.txt")
|
||||
or
|
||||
RENAME \input.txt TO \output.txt
|
||||
11
Task/Rename-a-file/Clojure/rename-a-file.clj
Normal file
11
Task/Rename-a-file/Clojure/rename-a-file.clj
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(import '(java.io File))
|
||||
|
||||
(.renameTo (File. "input.txt") (File. "output.txt"))
|
||||
(.renameTo (File. "docs") (File. "mydocs"))
|
||||
|
||||
(.renameTo
|
||||
(File. (str (File/separator) "input.txt"))
|
||||
(File. (str (File/separator) "output.txt")))
|
||||
(.renameTo
|
||||
(File. (str (File/separator) "docs"))
|
||||
(File. (str (File/separator) "mydocs")))
|
||||
1
Task/Rename-a-file/Commodore-BASIC/rename-a-file-1.basic
Normal file
1
Task/Rename-a-file/Commodore-BASIC/rename-a-file-1.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
OPEN 15,<Device>,15,"R<DRIVE>:FilenameOLD=FilenameNEW":CLOSE 15
|
||||
1
Task/Rename-a-file/Commodore-BASIC/rename-a-file-2.basic
Normal file
1
Task/Rename-a-file/Commodore-BASIC/rename-a-file-2.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
RENAME <FilenameOLD>[,D<DRIVE>] TO <FilenameNEW> [ON U<Deviceadress>]
|
||||
4
Task/Rename-a-file/Common-Lisp/rename-a-file.lisp
Normal file
4
Task/Rename-a-file/Common-Lisp/rename-a-file.lisp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(rename-file "input.txt" "output.txt")
|
||||
(rename-file "docs" "mydocs")
|
||||
(rename-file "/input.txt" "/output.txt")
|
||||
(rename-file "/docs" "/mydocs")
|
||||
4
Task/Rename-a-file/D/rename-a-file.d
Normal file
4
Task/Rename-a-file/D/rename-a-file.d
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
std.file.rename("input.txt","output.txt");
|
||||
std.file.rename("/input.txt","/output.txt");
|
||||
std.file.rename("docs","mydocs");
|
||||
std.file.rename("/docs","/mydocs");
|
||||
10
Task/Rename-a-file/DBL/rename-a-file.dbl
Normal file
10
Task/Rename-a-file/DBL/rename-a-file.dbl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
XCALL RENAM ("output.txt","input.txt")
|
||||
.IFDEF UNIX
|
||||
XCALL SPAWN ("mv docs mydocs")
|
||||
.ENDC
|
||||
.IFDEF DOS
|
||||
XCALL SPAWN ("ren docs mydocs")
|
||||
.ENDC
|
||||
.IFDEF VMS
|
||||
XCALL SPAWN ("rename docs.dir mydocs.dir")
|
||||
.ENDC
|
||||
4
Task/Rename-a-file/DCL/rename-a-file.dcl
Normal file
4
Task/Rename-a-file/DCL/rename-a-file.dcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
rename input.txt output.txt
|
||||
rename docs.dir mydocs.dir
|
||||
rename [000000]input.txt [000000]output.txt
|
||||
rename [000000]docs.dir [000000]mydocs.dir
|
||||
14
Task/Rename-a-file/Delphi/rename-a-file.delphi
Normal file
14
Task/Rename-a-file/Delphi/rename-a-file.delphi
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
program RenameFile;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
begin
|
||||
SysUtils.RenameFile('input.txt', 'output.txt');
|
||||
SysUtils.RenameFile('\input.txt', '\output.txt');
|
||||
|
||||
// RenameFile works for both files and folders
|
||||
SysUtils.RenameFile('docs', 'MyDocs');
|
||||
SysUtils.RenameFile('\docs', '\MyDocs');
|
||||
end.
|
||||
4
Task/Rename-a-file/E/rename-a-file.e
Normal file
4
Task/Rename-a-file/E/rename-a-file.e
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
for where in [<file:.>, <file:///>] {
|
||||
where["input.txt"].renameTo(where["output.txt"], null)
|
||||
where["docs"].renameTo(where["mydocs"], null)
|
||||
}
|
||||
4
Task/Rename-a-file/Elixir/rename-a-file.elixir
Normal file
4
Task/Rename-a-file/Elixir/rename-a-file.elixir
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
File.rename "input.txt","output.txt"
|
||||
File.rename "docs", "mydocs"
|
||||
File.rename "/input.txt", "/output.txt"
|
||||
File.rename "/docs", "/mydocs"
|
||||
4
Task/Rename-a-file/Emacs-Lisp/rename-a-file.l
Normal file
4
Task/Rename-a-file/Emacs-Lisp/rename-a-file.l
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(rename-file "input.txt" "output.txt")
|
||||
(rename-file "/input.txt" "/output.txt")
|
||||
(rename-file "docs" "mydocs")
|
||||
(rename-file "/docs" "/mydocs")
|
||||
4
Task/Rename-a-file/Erlang/rename-a-file.erl
Normal file
4
Task/Rename-a-file/Erlang/rename-a-file.erl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
file:rename("input.txt","output.txt"),
|
||||
file:rename( "docs", "mydocs" ),
|
||||
file:rename( "/input.txt", "/output.txt" ),
|
||||
file:rename( "/docs", "/mydocs" ).
|
||||
9
Task/Rename-a-file/F-Sharp/rename-a-file.fs
Normal file
9
Task/Rename-a-file/F-Sharp/rename-a-file.fs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
open System.IO
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
File.Move("input.txt","output.txt")
|
||||
File.Move(@"\input.txt",@"\output.txt")
|
||||
Directory.Move("docs","mydocs")
|
||||
Directory.Move(@"\docs",@"\mydocs")
|
||||
0
|
||||
3
Task/Rename-a-file/Factor/rename-a-file.factor
Normal file
3
Task/Rename-a-file/Factor/rename-a-file.factor
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
"" "/" [
|
||||
[ "input.txt" "output.txt" move-file "docs" "mydocs" move-file ] with-directory
|
||||
] bi@
|
||||
12
Task/Rename-a-file/Fantom/rename-a-file.fantom
Normal file
12
Task/Rename-a-file/Fantom/rename-a-file.fantom
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class Rename
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
// rename file/dir in current directory
|
||||
File.rename("input.txt".toUri).rename("output.txt")
|
||||
File.rename("docs/".toUri).rename("mydocs/")
|
||||
// rename file/dir in root directory
|
||||
File.rename("/input.txt".toUri).rename("/output.txt")
|
||||
File.rename("/docs/".toUri).rename("/mydocs/")
|
||||
}
|
||||
}
|
||||
2
Task/Rename-a-file/Forth/rename-a-file.fth
Normal file
2
Task/Rename-a-file/Forth/rename-a-file.fth
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
s" input.txt" s" output.txt" rename-file throw
|
||||
s" /input.txt" s" /output.txt" rename-file throw
|
||||
6
Task/Rename-a-file/Fortran/rename-a-file.f
Normal file
6
Task/Rename-a-file/Fortran/rename-a-file.f
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
PROGRAM EX_RENAME
|
||||
CALL RENAME('input.txt','output.txt')
|
||||
CALL RENAME('docs','mydocs')
|
||||
CALL RENAME('/input.txt','/output.txt')
|
||||
CALL RENAME('/docs','/mydocs')
|
||||
END
|
||||
14
Task/Rename-a-file/FreeBASIC/rename-a-file.basic
Normal file
14
Task/Rename-a-file/FreeBASIC/rename-a-file.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim result As Long
|
||||
result = Name("input.txt", "output.txt")
|
||||
If result <> 0 Then
|
||||
Print "Renaming file failed"
|
||||
End If
|
||||
|
||||
result = Name("docs", "mydocs")
|
||||
If result <> 0 Then
|
||||
Print "Renaming directory failed"
|
||||
End If
|
||||
|
||||
Sleep
|
||||
8
Task/Rename-a-file/FutureBasic/rename-a-file.basic
Normal file
8
Task/Rename-a-file/FutureBasic/rename-a-file.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CFURLRef inputText, outputText, docs, myDocs
|
||||
inputText = fn URLFileURLWithPath( @"~/Desktop/input.txt" )
|
||||
outputText = fn URLFileURLWithPath( @"~/Desktop/output.txt" )
|
||||
docs = fn URLFileURLWithPath( @"~/Desktop/docs/" )
|
||||
myDocs = fn URLFileURLWithPath( @"~/Desktop/myDocs/" )
|
||||
|
||||
fn FileManagerMoveItemAtURL( inputText, outputText )
|
||||
fn FileManagerMoveItemAtURL( docs, myDocs )
|
||||
9
Task/Rename-a-file/Go/rename-a-file.go
Normal file
9
Task/Rename-a-file/Go/rename-a-file.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
import "os"
|
||||
|
||||
func main() {
|
||||
os.Rename("input.txt", "output.txt")
|
||||
os.Rename("docs", "mydocs")
|
||||
os.Rename("/input.txt", "/output.txt")
|
||||
os.Rename("/docs", "/mydocs")
|
||||
}
|
||||
5
Task/Rename-a-file/Groovy/rename-a-file-1.groovy
Normal file
5
Task/Rename-a-file/Groovy/rename-a-file-1.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
|
||||
['.', ''].each { dir ->
|
||||
new File("$dir/$src").renameTo(new File("$dir/$dst"))
|
||||
}
|
||||
}
|
||||
5
Task/Rename-a-file/Groovy/rename-a-file-2.groovy
Normal file
5
Task/Rename-a-file/Groovy/rename-a-file-2.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
['input.txt':'output.txt', 'docs':'mydocs'].each { src, dst ->
|
||||
['.', ''].each { dir ->
|
||||
new AntBuilder().move(file:"$dir/$src", toFile:"$dir/$dst")
|
||||
}
|
||||
}
|
||||
5
Task/Rename-a-file/Harbour/rename-a-file.harbour
Normal file
5
Task/Rename-a-file/Harbour/rename-a-file.harbour
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
FRename( "input.txt","output.txt")
|
||||
// or
|
||||
RENAME input.txt TO output.txt
|
||||
|
||||
FRename( hb_ps() + "input.txt", hb_ps() + "output.txt")
|
||||
8
Task/Rename-a-file/Haskell/rename-a-file.hs
Normal file
8
Task/Rename-a-file/Haskell/rename-a-file.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import System.IO
|
||||
import System.Directory
|
||||
|
||||
main = do
|
||||
renameFile "input.txt" "output.txt"
|
||||
renameDirectory "docs" "mydocs"
|
||||
renameFile "/input.txt" "/output.txt"
|
||||
renameDirectory "/docs" "/mydocs"
|
||||
7
Task/Rename-a-file/HicEst/rename-a-file.hicest
Normal file
7
Task/Rename-a-file/HicEst/rename-a-file.hicest
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
WRITE(FIle='input.txt', REName='.\output.txt')
|
||||
SYSTEM(DIR='E:\HicEst\Rosetta')
|
||||
WRITE(FIle='.\docs', REName='.\mydocs')
|
||||
|
||||
WRITE(FIle='\input.txt', REName='\output.txt')
|
||||
SYSTEM(DIR='\')
|
||||
WRITE(FIle='\docs', REName='\mydocs')
|
||||
4
Task/Rename-a-file/Icon/rename-a-file.icon
Normal file
4
Task/Rename-a-file/Icon/rename-a-file.icon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
every dir := !["./","/"] do {
|
||||
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)
|
||||
}
|
||||
15
Task/Rename-a-file/Io/rename-a-file.io
Normal file
15
Task/Rename-a-file/Io/rename-a-file.io
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// rename file in current directory
|
||||
f := File with("input.txt")
|
||||
f moveTo("output.txt")
|
||||
|
||||
// rename file in root directory
|
||||
f := File with("/input.txt")
|
||||
f moveTo("/output.txt")
|
||||
|
||||
// rename directory in current directory
|
||||
d := Directory with("docs")
|
||||
d moveTo("mydocs")
|
||||
|
||||
// rename directory in root directory
|
||||
d := Directory with("/docs")
|
||||
d moveTo("/mydocs")
|
||||
9
Task/Rename-a-file/J/rename-a-file-1.j
Normal file
9
Task/Rename-a-file/J/rename-a-file-1.j
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
frename=: 4 : 0
|
||||
if. x -: y do. return. end.
|
||||
if. IFUNIX do.
|
||||
hostcmd=. [: 2!:0 '('"_ , ] , ' || true)'"_
|
||||
hostcmd 'mv "',y,'" "',x,'"'
|
||||
else.
|
||||
'kernel32 MoveFileA i *c *c' 15!:0 y;x
|
||||
end.
|
||||
)
|
||||
4
Task/Rename-a-file/J/rename-a-file-2.j
Normal file
4
Task/Rename-a-file/J/rename-a-file-2.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
'output.txt' frename 'input.txt'
|
||||
'/output.txt' frename '/input.txt'
|
||||
'mydocs' frename 'docs'
|
||||
'/mydocs' frename '/docs'
|
||||
26
Task/Rename-a-file/Java/rename-a-file.java
Normal file
26
Task/Rename-a-file/Java/rename-a-file.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import java.io.File;
|
||||
public class FileRenameTest {
|
||||
public static boolean renameFile(String oldname, String newname) {
|
||||
// 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);
|
||||
return success;
|
||||
}
|
||||
public static void test(String type, String oldname, String newname) {
|
||||
System.out.println("The following " + type + " called " + oldname +
|
||||
( renameFile(oldname, newname) ? " was renamed as " : " could not be renamed into ")
|
||||
+ newname + "."
|
||||
);
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
test("file", "input.txt", "output.txt");
|
||||
test("file", File.separator + "input.txt", File.separator + "output.txt");
|
||||
test("directory", "docs", "mydocs");
|
||||
test("directory", File.separator + "docs" + File.separator, File.separator + "mydocs" + File.separator);
|
||||
}
|
||||
}
|
||||
5
Task/Rename-a-file/JavaScript/rename-a-file.js
Normal file
5
Task/Rename-a-file/JavaScript/rename-a-file.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var fso = new ActiveXObject("Scripting.FileSystemObject")
|
||||
fso.MoveFile("input.txt", "output.txt")
|
||||
fso.MoveFile("c:/input.txt", "c:/output.txt")
|
||||
fso.MoveFolder("docs", "mydocs")
|
||||
fso.MoveFolder("c:/docs", "c:/mydocs")
|
||||
4
Task/Rename-a-file/Joy/rename-a-file.joy
Normal file
4
Task/Rename-a-file/Joy/rename-a-file.joy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"input.txt" "output.txt" frename
|
||||
"/input.txt" "/output.txt" frename
|
||||
"docs" "mydocs" frename
|
||||
"/docs" "/mydocs" frename.
|
||||
9
Task/Rename-a-file/Jsish/rename-a-file.jsish
Normal file
9
Task/Rename-a-file/Jsish/rename-a-file.jsish
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* File rename, in jsish */
|
||||
try { File.rename('input.txt', 'output.txt', false); } catch (str) { puts(str); }
|
||||
|
||||
exec('touch input.txt');
|
||||
puts("overwrite set true if output.txt exists");
|
||||
File.rename('input.txt', 'output.txt', true);
|
||||
|
||||
try { File.rename('docs', 'mydocs', false); } catch (str) { puts(str); }
|
||||
try { File.rename('/docs', '/mydocs', false); } catch (str) { puts(str); }
|
||||
4
Task/Rename-a-file/Julia/rename-a-file.julia
Normal file
4
Task/Rename-a-file/Julia/rename-a-file.julia
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
mv("input.txt", "output.txt")
|
||||
mv("docs", "mydocs")
|
||||
mv("/input.txt", "/output.txt")
|
||||
mv("/docs", "/mydocs")
|
||||
21
Task/Rename-a-file/Kotlin/rename-a-file.kotlin
Normal file
21
Task/Rename-a-file/Kotlin/rename-a-file.kotlin
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// version 1.0.6
|
||||
|
||||
/* testing on Windows 10 which needs administrative privileges
|
||||
to rename files in the root */
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val oldPaths = arrayOf("input.txt", "docs", "c:\\input.txt", "c:\\docs")
|
||||
val newPaths = arrayOf("output.txt", "mydocs", "c:\\output.txt", "c:\\mydocs")
|
||||
var oldFile: File
|
||||
var newFile: File
|
||||
for (i in 0 until oldPaths.size) {
|
||||
oldFile = File(oldPaths[i])
|
||||
newFile = File(newPaths[i])
|
||||
if (oldFile.renameTo(newFile))
|
||||
println("${oldPaths[i]} successfully renamed to ${newPaths[i]}")
|
||||
else
|
||||
println("${oldPaths[i]} could not be renamed")
|
||||
}
|
||||
}
|
||||
4
Task/Rename-a-file/LFE/rename-a-file.lfe
Normal file
4
Task/Rename-a-file/LFE/rename-a-file.lfe
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(file:rename "input.txt" "output.txt")
|
||||
(file:rename "docs" "mydocs")
|
||||
(file:rename "/input.txt" "/output.txt")
|
||||
(file:rename "/docs" "/mydocs")
|
||||
18
Task/Rename-a-file/Lang/rename-a-file.lang
Normal file
18
Task/Rename-a-file/Lang/rename-a-file.lang
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Load the IO module
|
||||
# Replace "<pathToIO.lm>" with the location where the io.lm Lang module was installed to without "<" and ">"
|
||||
ln.loadModule(<pathToIO.lm>)
|
||||
|
||||
fp.rename = ($from, $to) -> {
|
||||
$fileFrom = [[io]]::fp.openFile($from)
|
||||
$fileTo = [[io]]::fp.openFile($to)
|
||||
|
||||
[[io]]::fp.rename($fileFrom, $fileTo)
|
||||
|
||||
[[io]]::fp.closeFile($fileFrom)
|
||||
[[io]]::fp.closeFile($fileTo)
|
||||
}
|
||||
|
||||
fp.rename(input.txt, output.txt)
|
||||
fp.rename(/input.txt, /output.txt)
|
||||
fp.rename(docs, mydocs)
|
||||
fp.rename(/docs, /mydocs)
|
||||
17
Task/Rename-a-file/Lasso/rename-a-file.lasso
Normal file
17
Task/Rename-a-file/Lasso/rename-a-file.lasso
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// move file
|
||||
local(f = file('input.txt'))
|
||||
#f->moveTo('output.txt')
|
||||
#f->close
|
||||
|
||||
// move directory, just like a file
|
||||
local(d = dir('docs'))
|
||||
#d->moveTo('mydocs')
|
||||
|
||||
// move file in root file system (requires permissions at user OS level)
|
||||
local(f = file('//input.txt'))
|
||||
#f->moveTo('//output.txt')
|
||||
#f->close
|
||||
|
||||
// move directory in root file system (requires permissions at user OS level)
|
||||
local(d = file('//docs'))
|
||||
#d->moveTo('//mydocs')
|
||||
10
Task/Rename-a-file/Liberty-BASIC/rename-a-file.basic
Normal file
10
Task/Rename-a-file/Liberty-BASIC/rename-a-file.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
' LB has inbuilt 'name' command, but can also run batch files
|
||||
|
||||
nomainwin
|
||||
|
||||
name "input.txt" as "output.txt"
|
||||
run "cmd.exe /c ren docs mydocs", HIDE
|
||||
name "C:\input.txt" as "C:\output.txt"
|
||||
run "cmd.exe /c ren C:\docs mydocs", HIDE
|
||||
|
||||
end
|
||||
4
Task/Rename-a-file/LiveCode/rename-a-file.livecode
Normal file
4
Task/Rename-a-file/LiveCode/rename-a-file.livecode
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
rename file "input.txt" to "output.txt"
|
||||
rename folder "docs" to "mydocs"
|
||||
rename file "/input.txt" to "/output.txt"
|
||||
rename folder "/docs" to "/mydocs"
|
||||
1
Task/Rename-a-file/Locomotive-Basic/rename-a-file.basic
Normal file
1
Task/Rename-a-file/Locomotive-Basic/rename-a-file.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
|ren,"input.txt","output.txt"
|
||||
4
Task/Rename-a-file/Lua/rename-a-file.lua
Normal file
4
Task/Rename-a-file/Lua/rename-a-file.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
os.rename( "input.txt", "output.txt" )
|
||||
os.rename( "/input.txt", "/output.txt" )
|
||||
os.rename( "docs", "mydocs" )
|
||||
os.rename( "/docs", "/mydocs" )
|
||||
10
Task/Rename-a-file/M2000-Interpreter/rename-a-file.m2000
Normal file
10
Task/Rename-a-file/M2000-Interpreter/rename-a-file.m2000
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Module checkit {
|
||||
Document A$={Alfa, beta}
|
||||
Save.Doc A$, "this.aaa"
|
||||
Print Exist("this.aaa")=true
|
||||
dos "cd "+quote$(dir$)+" && del this.bbb", 100; ' using; to close dos window, and 100ms for waiting
|
||||
Name this.aaa as this.bbb
|
||||
Rem : Name "this.aaa" as "this.bbb" ' we can use strings or variables
|
||||
Print Exist("this.bbb")=true
|
||||
}
|
||||
checkit
|
||||
1
Task/Rename-a-file/MATLAB/rename-a-file.m
Normal file
1
Task/Rename-a-file/MATLAB/rename-a-file.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
[STATUS, MSG, MSGID] = movefile (F1, F2);
|
||||
4
Task/Rename-a-file/MAXScript/rename-a-file.max
Normal file
4
Task/Rename-a-file/MAXScript/rename-a-file.max
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
-- Here
|
||||
renameFile "input.txt" "output.txt"
|
||||
-- Root
|
||||
renameFile "/input.txt" "/output.txt"
|
||||
6
Task/Rename-a-file/MUMPS/rename-a-file.mumps
Normal file
6
Task/Rename-a-file/MUMPS/rename-a-file.mumps
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
;Local
|
||||
S X=$ZF(-1,"rename input.txt output.txt")
|
||||
S X=$ZF(-1,"rename docs.dir mydocs.dir")
|
||||
;Root of current device
|
||||
S X=$ZF(-1,"rename [000000]input.txt [000000]output.txt")
|
||||
S X=$ZF(-1,"rename [000000]docs.dir [000000]mydocs.dir")
|
||||
6
Task/Rename-a-file/Maple/rename-a-file.maple
Normal file
6
Task/Rename-a-file/Maple/rename-a-file.maple
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use FileTools in
|
||||
Rename( "input.txt", "output.txt" );
|
||||
Rename( "docs", "mydocs" );
|
||||
Rename( "/input.txt", "/output.txt" ); # assuming permissions in /
|
||||
Rename( "/docs", "/mydocs" ) # assuming permissions in /
|
||||
end use:
|
||||
6
Task/Rename-a-file/Mathematica/rename-a-file.math
Normal file
6
Task/Rename-a-file/Mathematica/rename-a-file.math
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
SetDirectory[NotebookDirectory[]]
|
||||
RenameFile["input.txt", "output.txt"]
|
||||
RenameDirectory["docs", "mydocs"]
|
||||
SetDirectory[$RootDirectory]
|
||||
RenameFile["input.txt", "output.txt"]
|
||||
RenameDirectory["docs", "mydocs"]
|
||||
34
Task/Rename-a-file/Mercury/rename-a-file.mercury
Normal file
34
Task/Rename-a-file/Mercury/rename-a-file.mercury
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
:- module rename_file.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- import_module dir.
|
||||
|
||||
main(!IO) :-
|
||||
rename_file("input.txt", "output.txt", !IO),
|
||||
rename_file("docs", "mydocs", !IO),
|
||||
rename_file("/input.txt", "/output.txt", !IO),
|
||||
rename_file("/docs", "/mydocs", !IO).
|
||||
|
||||
:- pred rename_file(string::in, string::in, io::di, io::uo) is det.
|
||||
|
||||
rename_file(OldName, NewName, !IO) :-
|
||||
io.rename_file(OldName, NewName, Result, !IO),
|
||||
(
|
||||
Result = ok
|
||||
;
|
||||
Result = error(Error),
|
||||
print_io_error(Error, !IO)
|
||||
).
|
||||
|
||||
:- pred print_io_error(io.error::in, io::di, io::uo) is det.
|
||||
|
||||
print_io_error(Error, !IO) :-
|
||||
io.stderr_stream(Stderr, !IO),
|
||||
io.write_string(Stderr, io.error_message(Error), !IO),
|
||||
io.nl(Stderr, !IO),
|
||||
io.set_exit_status(1, !IO).
|
||||
5
Task/Rename-a-file/Min/rename-a-file.min
Normal file
5
Task/Rename-a-file/Min/rename-a-file.min
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"input.txt" "output.txt" mv
|
||||
"docs" "mydocs" mv
|
||||
|
||||
"/input.txt" "/output.txt" mv
|
||||
"/docs" "/mydocs" mv
|
||||
36
Task/Rename-a-file/NetRexx/rename-a-file.netrexx
Normal file
36
Task/Rename-a-file/NetRexx/rename-a-file.netrexx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols binary
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
method isFileRenamed(oldFile, newFile) public static returns boolean
|
||||
fo = File(oldFile)
|
||||
fn = File(newFile)
|
||||
fRenamed = fo.renameTo(fn)
|
||||
return fRenamed
|
||||
|
||||
-- 09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)09:11, 27 August 2022 (UTC)~~
|
||||
method runSample(arg) private static
|
||||
parse arg files
|
||||
if files = '' then files = 'input.txt output.txt F docs mydocs D /input.txt /output.txt F /docs /mydocs D'
|
||||
loop while files.length > 0
|
||||
parse files of nf ft files
|
||||
select case(ft.upper())
|
||||
when 'F' then do
|
||||
ft = 'File'
|
||||
end
|
||||
when 'D' then do
|
||||
ft = 'Directory'
|
||||
end
|
||||
otherwise do
|
||||
ft = 'File'
|
||||
end
|
||||
end
|
||||
if isFileRenamed(of, nf) then dl = 'renamed'
|
||||
else dl = 'not renamed'
|
||||
say ft ''''of'''' dl 'to' nf
|
||||
end
|
||||
|
||||
return
|
||||
4
Task/Rename-a-file/NewLISP/rename-a-file.l
Normal file
4
Task/Rename-a-file/NewLISP/rename-a-file.l
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(rename-file "./input.txt" "./output.txt")
|
||||
(rename-file "./docs" "./mydocs")
|
||||
(rename-file "/input.txt" "/output.txt")
|
||||
(rename-file "/docs" "/mydocs")
|
||||
7
Task/Rename-a-file/Nim/rename-a-file.nim
Normal file
7
Task/Rename-a-file/Nim/rename-a-file.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import os
|
||||
|
||||
moveFile("input.txt", "output.txt")
|
||||
moveFile("docs", "mydocs")
|
||||
|
||||
moveFile(DirSep & "input.txt", DirSep & "output.txt")
|
||||
moveFile(DirSep & "docs", DirSep & "mydocs")
|
||||
5
Task/Rename-a-file/OCaml/rename-a-file.ocaml
Normal file
5
Task/Rename-a-file/OCaml/rename-a-file.ocaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let () =
|
||||
Sys.rename "input.txt" "output.txt";
|
||||
Sys.rename "docs" "mydocs";
|
||||
Sys.rename "/input.txt" "/output.txt";
|
||||
Sys.rename "/docs" "/mydocs";
|
||||
11
Task/Rename-a-file/Objeck/rename-a-file.objeck
Normal file
11
Task/Rename-a-file/Objeck/rename-a-file.objeck
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use IO;
|
||||
bundle Default {
|
||||
class FileExample {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
File->Rename("input.txt", "output.txt");
|
||||
File->Rename("docs", "mydocs");
|
||||
File->Rename("/input.txt", "/output.txt");
|
||||
File->Rename("/docs", "/mydocs");
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Task/Rename-a-file/Objective-C/rename-a-file.m
Normal file
9
Task/Rename-a-file/Objective-C/rename-a-file.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
||||
// Pre-OS X 10.5
|
||||
[fm movePath:@"input.txt" toPath:@"output.txt" handler:nil];
|
||||
[fm movePath:@"docs" toPath:@"mydocs" handler:nil];
|
||||
|
||||
// OS X 10.5+
|
||||
[fm moveItemAtPath:@"input.txt" toPath:@"output.txt" error:NULL];
|
||||
[fm moveItemAtPath:@"docs" toPath:@"mydocs" error:NULL];
|
||||
3
Task/Rename-a-file/Octave/rename-a-file.octave
Normal file
3
Task/Rename-a-file/Octave/rename-a-file.octave
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
rename('docs','mydocs');
|
||||
rename('input.txt','/output.txt');
|
||||
rename('/docs','/mydocs');
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
OS-RENAME "input.txt" "output.txt".
|
||||
OS-RENAME "docs" "mydocs".
|
||||
|
||||
OS-RENAME "/input.txt" "/output.txt".
|
||||
OS-RENAME "/docs" "/mydocs".
|
||||
4
Task/Rename-a-file/PARI-GP/rename-a-file-1.parigp
Normal file
4
Task/Rename-a-file/PARI-GP/rename-a-file-1.parigp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
system("mv input.txt output.txt");
|
||||
system("mv /input.txt /output.txt");
|
||||
system("mv docs mydocs");
|
||||
system("mv /docs /mydocs");
|
||||
2
Task/Rename-a-file/PARI-GP/rename-a-file-2.parigp
Normal file
2
Task/Rename-a-file/PARI-GP/rename-a-file-2.parigp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
install("rename","iss","rename");
|
||||
rename("input.txt", "output.txt");
|
||||
6
Task/Rename-a-file/PHP/rename-a-file.php
Normal file
6
Task/Rename-a-file/PHP/rename-a-file.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
rename('input.txt', 'output.txt');
|
||||
rename('docs', 'mydocs');
|
||||
rename('/input.txt', '/output.txt');
|
||||
rename('/docs', '/mydocs');
|
||||
?>
|
||||
22
Task/Rename-a-file/Pascal/rename-a-file.pas
Normal file
22
Task/Rename-a-file/Pascal/rename-a-file.pas
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
var
|
||||
f : file ; // Untyped file
|
||||
begin
|
||||
|
||||
// as current directory
|
||||
AssignFile(f,'input.doc');
|
||||
Rename(f,'output.doc');
|
||||
|
||||
// as root directory
|
||||
AssignFile(f,'\input.doc');
|
||||
Rename(f,'\output.doc');
|
||||
|
||||
// rename a directory
|
||||
AssignFile(f,'docs');
|
||||
Rename(f,'mydocs');
|
||||
|
||||
//rename a directory off the root
|
||||
|
||||
AssignFile(f,'\docs');
|
||||
Rename(f,'\mydocs');
|
||||
|
||||
end;
|
||||
8
Task/Rename-a-file/Perl/rename-a-file.pl
Normal file
8
Task/Rename-a-file/Perl/rename-a-file.pl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use File::Copy qw(move);
|
||||
use File::Spec::Functions qw(catfile rootdir);
|
||||
# here
|
||||
move 'input.txt', 'output.txt';
|
||||
move 'docs', 'mydocs';
|
||||
# root dir
|
||||
move (catfile rootdir, 'input.txt'), (catfile rootdir, 'output.txt');
|
||||
move (catfile rootdir, 'docs'), (catfile rootdir, 'mydocs');
|
||||
7
Task/Rename-a-file/Phix/rename-a-file.phix
Normal file
7
Task/Rename-a-file/Phix/rename-a-file.phix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(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: #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;">"docs"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"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:\\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>
|
||||
<!--
|
||||
7
Task/Rename-a-file/Phixmonti/rename-a-file.phixmonti
Normal file
7
Task/Rename-a-file/Phixmonti/rename-a-file.phixmonti
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
_platform "windows" == if "\\" "ren " else "/" "mv " endif
|
||||
var com var slash
|
||||
|
||||
com "input.txt output.txt" chain cmd
|
||||
com "docs mydocs" chain cmd
|
||||
com slash chain "input.txt " chain slash chain "output.txt" chain cmd
|
||||
com slash chain "docs " chain slash chain "mydocs" chain cmd
|
||||
4
Task/Rename-a-file/PicoLisp/rename-a-file.l
Normal file
4
Task/Rename-a-file/PicoLisp/rename-a-file.l
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(call 'mv "input.txt" "output.txt")
|
||||
(call 'mv "docs" "mydocs")
|
||||
(call 'mv "/input.txt" "/output.txt")
|
||||
(call 'mv "/docs" "/mydocs")
|
||||
6
Task/Rename-a-file/Pike/rename-a-file.pike
Normal file
6
Task/Rename-a-file/Pike/rename-a-file.pike
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
int main(){
|
||||
mv("input.txt", "output.txt");
|
||||
mv("/input.txt", "/output.txt");
|
||||
mv("docs", "mydocs");
|
||||
mv("/docs", "/mydocs");
|
||||
}
|
||||
9
Task/Rename-a-file/Plain-English/rename-a-file.plain
Normal file
9
Task/Rename-a-file/Plain-English/rename-a-file.plain
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
To run:
|
||||
Start up.
|
||||
\ In the current working directory
|
||||
Rename ".\input.txt" to ".\output.txt" in the file system.
|
||||
Rename ".\docs\" to ".\mydocs\" in the file system.
|
||||
\ In the filesystem root
|
||||
Rename "C:\input.txt" to "C:\output.txt" in the file system.
|
||||
Rename "C:\docs\" to "C:\mydocs\" in the file system.
|
||||
Shut down.
|
||||
4
Task/Rename-a-file/Pop11/rename-a-file.pop11
Normal file
4
Task/Rename-a-file/Pop11/rename-a-file.pop11
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
sys_file_move('inputs.txt', 'output.txt');
|
||||
sys_file_move('docs', 'mydocs');
|
||||
sys_file_move('/inputs.txt', '/output.txt');
|
||||
sys_file_move(/'docs', '/mydocs');
|
||||
4
Task/Rename-a-file/PowerShell/rename-a-file.psh
Normal file
4
Task/Rename-a-file/PowerShell/rename-a-file.psh
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Rename-Item input.txt output.txt
|
||||
|
||||
# The Rename-item has the alias ren
|
||||
ren input.txt output.txt
|
||||
2
Task/Rename-a-file/ProDOS/rename-a-file.dos
Normal file
2
Task/Rename-a-file/ProDOS/rename-a-file.dos
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
rename input.txt to output.txt
|
||||
rename docs to mydocs
|
||||
19
Task/Rename-a-file/Processing/rename-a-file-1.processing
Normal file
19
Task/Rename-a-file/Processing/rename-a-file-1.processing
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
void setup(){
|
||||
boolean sketchfile = rename(sketchPath("input.txt"), sketchPath("output.txt"));
|
||||
boolean sketchfold = rename(sketchPath("docs"), sketchPath("mydocs"));
|
||||
// sketches will seldom have write permission to root files/folders
|
||||
boolean rootfile = rename("input.txt", "output.txt");
|
||||
boolean rootfold = rename("docs", "mydocs");
|
||||
// true if succeeded, false if failed
|
||||
println(sketchfile, sketchfold, rootfile, rootfold);
|
||||
}
|
||||
|
||||
boolean rename(String oldname, String newname) {
|
||||
// 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);
|
||||
return success;
|
||||
}
|
||||
29
Task/Rename-a-file/Processing/rename-a-file-2.processing
Normal file
29
Task/Rename-a-file/Processing/rename-a-file-2.processing
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from java.io import File
|
||||
|
||||
def setup():
|
||||
# rename local file
|
||||
sketchfile = rename(sketchPath("input.txt"), sketchPath("output.txt"))
|
||||
# rename local folder
|
||||
sketchfold = rename(sketchPath("docs"), sketchPath("mydocs"))
|
||||
# rename root file (if permitted)
|
||||
rootfile = rename("input.txt", "output.txt")
|
||||
# rename root folder (if permitted)
|
||||
rootfold = rename("docs", "mydocs")
|
||||
|
||||
# display results of four operations: True=success, False=fail
|
||||
println(str(sketchfile) + ' ' +
|
||||
str(sketchfold) + ' ' +
|
||||
str(rootfile) + ' ' +
|
||||
str(rootfold))
|
||||
# output:
|
||||
# True True False False
|
||||
|
||||
|
||||
def rename(oldname, newname):
|
||||
# File (or directory) with old name
|
||||
file = File(oldname)
|
||||
# File (or directory) with new name
|
||||
file2 = File(newname)
|
||||
# Rename file (or directory)
|
||||
success = file.renameTo(file2)
|
||||
return success
|
||||
5
Task/Rename-a-file/PureBasic/rename-a-file.basic
Normal file
5
Task/Rename-a-file/PureBasic/rename-a-file.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
RenameFile("input.txt", "output.txt")
|
||||
RenameFile("docs\", "mydocs\")
|
||||
|
||||
RenameFile("/input.txt","/output.txt")
|
||||
RenameFile("/docs\","/mydocs\")
|
||||
7
Task/Rename-a-file/Python/rename-a-file-1.py
Normal file
7
Task/Rename-a-file/Python/rename-a-file-1.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import os
|
||||
|
||||
os.rename("input.txt", "output.txt")
|
||||
os.rename("docs", "mydocs")
|
||||
|
||||
os.rename(os.sep + "input.txt", os.sep + "output.txt")
|
||||
os.rename(os.sep + "docs", os.sep + "mydocs")
|
||||
7
Task/Rename-a-file/Python/rename-a-file-2.py
Normal file
7
Task/Rename-a-file/Python/rename-a-file-2.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import shutil
|
||||
|
||||
shutil.move("input.txt", "output.txt")
|
||||
shutil.move("docs", "mydocs")
|
||||
|
||||
shutil.move("/input.txt", "/output.txt")
|
||||
shutil.move("/docs", "/mydocs")
|
||||
23
Task/Rename-a-file/Quackery/rename-a-file.quackery
Normal file
23
Task/Rename-a-file/Quackery/rename-a-file.quackery
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
$ "
|
||||
import os
|
||||
if os.path.exists('input.txt'):
|
||||
os.rename('input.txt', 'output.txt')
|
||||
" python
|
||||
|
||||
$ "
|
||||
import os
|
||||
if os.path.exists('docs'):
|
||||
os.rename('docs', 'mydocs')
|
||||
" python
|
||||
|
||||
$ "
|
||||
import os
|
||||
if os.path.exists('/input.txt'):
|
||||
os.rename('/input.txt', '/output.txt')
|
||||
" python
|
||||
|
||||
$ "
|
||||
import os
|
||||
if os.path.exists('/docs'):
|
||||
os.rename('/docs', '/mydocs')
|
||||
" python
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue