Rename a file: Difference between revisions
Content added Content deleted
m (Add libheader to the lang example) |
|||
Line 1,302: | Line 1,302: | ||
</syntaxhighlight> |
</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}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby">File.rename('input.txt', 'output.txt') |
<syntaxhighlight lang="ruby">File.rename('input.txt', 'output.txt') |