Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : OS-RENAME statement
 

OS-RENAME statement

Executes an operating system file rename or directory rename command from within ABL.

Syntax

OS-RENAME
{ source-filename | VALUE ( expression ) }
{ target-filename | VALUE ( expression ) }
source-filename
The name of the file or directory to rename. The file or directory name can contain Unicode characters. See OpenEdge Development: Internationalizing Applications for more information about Unicode.
VALUE ( expression )
An expression that returns the name of the file or directory to rename. expression can contain constants, field names, and variable names. The file or directory name can contain Unicode characters.
target-filename
The new name of the file or directory. The file or directory name can contain Unicode characters.
VALUE ( expression )
An expression that returns the new name of the file or directory. expression can contain constants, field names, and variable names. The file or directory name can contain Unicode characters.

Example

This procedure opens a dialog box that prompts the user to choose a file to rename. It then prompts for a new name. Finally, the procedure uses the OS-RENAME statement to rename the file.
r-os-nam.p
DEFINE VARIABLE sourcefile AS CHARACTER NO-UNDO.
DEFINE VARIABLE targetfile AS CHARACTER NO-UNDO FORMAT "x(20)"
  VIEW-AS FILL-IN.
DEFINE VARIABLE OKpressed  AS LOGICAL   NO-UNDO INITIAL TRUE.

Main:
REPEAT:
SYSTEM-DIALOG GET-FILE sourcefile
TITLE "Choose a File or Directory to Rename"
MUST-EXIST
USE-FILENAME
UPDATE OKpressed.
IF OKpressed = FALSE THEN
LEAVE Main.
UPDATE targetfile WITH FRAME newnameframe.
OS-RENAME VALUE(sourcefile) VALUE(targetfile).
END.

Notes

*The filenames or directory names must conform to the naming conventions of the underlying operating system.
*If source-filename and target-filename specify different directories, this statement both renames the file and moves it to the new directory.
*Although an error can occur during execution of this statement, the statement does not generate an error message, raise an error condition, or affect the program's flow in any way. Check for an execution error by using the OS-ERROR function and evaluating the return.

See also

OS-ERROR function