Syntax:

RENAMEFILE(original_name,new_name)

  • original_file_name: The file name of the file to be renamed. No path is allowed in this parameter, the file to be renamed must be in the current remote directory (see CHDIR).
  • new_file_name: The new file name.

Remarks:

  • For renaming multiple files two methods exist:
    # Method 1
     
    # Get the remote file listing, store it in $list
    $result=GETLIST($list,REMOTE_FILES,"*.txt")
     
    # For each file in $list...
    FOREACH $item IN $list
    # Rename a file adding a prefix to the
    # current file name
    RENAMEFILE($item,"myprefix-".$item)
    END FOREACH
     
    # Method 2
    # Only works with file extensions
     
    # Rename all jpg files to jpeg
    RENAMEFILE("*.jpg","*.jpeg")
     
    # Rename *2005.doc to *.doc.sav
    RENAMEFILE("*.2005.doc","*.doc.sav")
  • Note that the RENAMEFILE command can also be used to move remote files in some servers. More information.

Return value:

RENAMEFILE will return “OK” once the files have been renamed successfully.
If the operation fails it will return an error code. You may retrieve the return value and execute various operations depending on this value. See Error handling.

Examples:

# Connect to server
OPENHOST("ftp.myhost.com","myuser","mypassword")
 
# Rename foo.txt
RENAMEFILE("foo.txt","foo2.sav")
 
# Close connection
CLOSEHOST
 
# Connect to server
OPENHOST("127.0.0.1","myuser","mypass")
 
# Change current remote dir to /files_to_rename
CHDIR("/files_to_rename")
 
# Rename lenore.jpg to lenore.sav
RENAMEFILE("lenore.jpg","lenore.sav")
 
# Rename notes.txt to notes-(date).txt
$current_date=GETDATE(FORMAT3)
$new_file_name="notes-".$current_date.".txt"
RENAMEFILE("notes.txt",$new_file_name)
 
# Shorter way:
RENAMEFILE("notes.txt","notes-".$current_date.".txt")
 
# Even shorter way:
RENAMEFILE("notes.txt","notes-".GETDATE(FORMAT3).".txt")
 
# Rename all jpg files to jpeg
RENAMEFILE("*.jpg","*.jpeg")
 
# Rename *2005.doc to *.doc.sav
RENAMEFILE("*2005.doc","*.doc.sav")
 
# Close connection
CLOSEHOST