Rename a file: Difference between revisions

m
(→‎min: add)
m (→‎{{header|Wren}}: Minor tidy)
 
(4 intermediate revisions by 2 users not shown)
Line 674:
c:\docs successfully renamed to c:\mydocs
</pre>
 
=={{header|Lang}}==
{{libheader|lang-io-module}}
<syntaxhighlight lang="lang">
# 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)
</syntaxhighlight>
 
=={{header|Lasso}}==
Line 1,279 ⟶ 1,302:
</syntaxhighlight>
 
=={{header|RPL}}==
RPL’s tree file system is made of variables, which can contain either programs or data, and directories. Variables and directories handling features are basic.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
PATH { HOME } == 1 ROT '''IFTE'''
→ old new here
≪ '''IF''' here NOT '''THEN''' PATH HOME '''END'''
'''IFERR''' old RCL '''THEN'''
new CRDIR PURGE
'''ELSE'''
new STO old PURGE '''END'''
'''IF''' here NOT '''THEN'''
2 OVER SIZE '''FOR''' j DUP j GET EVAL '''NEXT'''
DROP '''END'''
≫ ≫ ''''RNAME'''' STO
|
'''RNAME''' ''( ‘old’ ‘new’ boolean -- )''
Set ''here'' to true if already at root
Store arguments
Store current path in stack and go to the root
Detect if ''old'' is a directory by recalling its content
If yes, create ''new'' then delete ''old''
Otherwise, store content in ''new'', then delete ''old''
Go back to current directory
following the path in stack
Forget path
|}
{{in}}
<pre>
'Input' 'Output' 1 RNAME
'DOCS' 'MYDOCS' 0 RNAME
</pre>
The boolean argument indicates if the renaming must be achieved in the current directory (1) or at the root (0).
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">File.rename('input.txt', 'output.txt')
Line 1,509 ⟶ 1,572:
{{libheader|Wren-ioutil}}
Wren-cli does not currently have the ability to rename directories, just files.
<syntaxhighlight lang="ecmascriptwren">import "./ioutil" for FileUtil
 
FileUtil.move("input.txt", "output.txt")
9,476

edits