Show/Hide Toolbars

XSharp

NoteThis command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available

Purpose

Change the name of a file to a new name.

Syntax

RENAME <xcSourceFile> TO <xcTargetFile>

Arguments

<xcSourceFile>The name of the source file to rename, including an optional drive, directory, and extension.  If <xcSourceFile> does not exist, a runtime error is raised.

 

TO <xcTargetFile>The name of the new file, including an optional drive, directory, and extension.  If <xcTargetFile> exists or is open, RENAME does nothing.
 
SetDefault() and SetPath() do not affect this command.  It assumes the current Windows drive and directory if none is specified.  No default extensions are supplied.

Description

If the target directory is different from the source directory, the file moves to the new directory.

 

Warning! Files must be closed before renaming.  Attempting to rename an open file will produce unpredictable results.  When a database file is renamed, remember that any associated memo file must also be renamed.  Failure to do so can compromise the integrity of your application.

Examples

This example renames a file, checking for the existence of the target file before beginning the RENAME operation:

 

xcOldFile := "oldfile.txt"
xcNewFile := "newfile.txt"
IF !File(xcNewFile)
 RENAME (xcOldFile) TO (xcNewFile)
ELSE
 ? "File already exists"
ENDIF

Assembly

XSharp.RT.DLL

See Also

COPY FILE, CurDir(), DELETE FILE, File(), FErase(), FRename(), RUN, SetDefault(), SetPath()