The professional tool to automate FTP and secure FTP transfers. Automated FTP & Batch FTP |
Rename remote files.
Syntax: RENAMEFILE(original_name,new_name)
Remarks:
# 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")
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