FileRename Statement:
Renames a file.
Description:
The FileRename Statement renames a file. There are two required arguments, oldFilePath and newFileName. The oldFilePath argument is the full path to the file you are renaming and the newFileName argument is the new name for the file.
Syntax:
Call FileRename(oldFilePath, NewFileName)
Example:
<%
Call FileRename("e:\inetpub\old.txt", "new.txt")
%>
ASP Source Code:
<%
Sub FileRename(byVal oldFilePath, byVal newFileName) Dim objFSO, boolErr, strErrDesc, filePath, numPos, newFile if not len(oldFilePath) = 0 then if instr(oldFilePath, "\") > 0 then numPos = InStrRev(oldFilePath, "\", len(oldFilePath)) elseif instr(oldFilePath, "/") > 0 then numPos = InStrRev(oldFilePath, "/", len(oldFilePath)) end if if numPos > 0 then filePath = Replace(oldFilePath, right(oldFilePath, len(oldFilePath) - numPos), "") newFile = filePath & newFileName end if end If On Error Resume Next Set objFSO = Server.CreateObject("scripting.filesystemobject") objFSO.MoveFile oldFilePath, newFile if Err Then boolErr = True strErrDesc = Err.Description end if Set objFSO = Nothing On Error GoTo 0 if boolErr then Err.Raise 5104, "FileRename Statement", strErrDesc End Sub
%>
|