Name


Function Name( old filename, new filename )


Returns 1 on success, 0 on failure to rename old filename to new filename.


Syntax Name("Test.txt", "Test.bak")


Remarks

Name will rename the file old filename to new filename with the following restrictions:


Files cannot be renamed across drives or directories.

For instance Name( "C:\temp\somefile.txt", "D:\work\newfile.txt") will fail because old filename and new filename are not in the same directory.

Files cannot be renamed if they are read-only.

Files cannot be renamed if they are open from within a script or are in use by another program.

Files cannot be renamed if new filename already exists.


See Also:

Kill File and Directory functions


Example Script


' rename temporary files to *.bak

STRING a,b

NUMBER i


CHDIR( "C:\TEMP" )

a = FINDFIRST("*.tmp")

WHILE LEN(a)

i = INSTR(a,".tmp") ' Case Insensitive (findfirst, findnext return all caps.)

b = LEFT(a,i)

b = b + "bak"

IF NAME(a,b) THEN

PRINT "Successfully renamed "; a; " to "; b

ELSE

PRINT "Failed to rename "; a; " to "; b

ENDIF

a = FINDNEXT()

WEND


Script Output


Successfully renamed ~DF1542.TMP to ~DF1542.bak

Successfully renamed ~DF16D2.TMP to ~DF16D2.bak

Successfully renamed ~DF346C.TMP to ~DF346C.bak

Successfully renamed ~DF3941.TMP to ~DF3941.bak

Successfully renamed ~DF40F9.TMP to ~DF40F9.bak

Successfully renamed ~DF46F4.TMP to ~DF46F4.bak

Successfully renamed ~DF46F5.TMP to ~DF46F5.bak

Successfully renamed ~DF4873.TMP to ~DF4873.bak

Successfully renamed ~DF4874.TMP to ~DF4874.bak

Successfully renamed ~DF14D4.TMP to ~DF14D4.bak