|
 |
asp_web_howto thread: Rename a File (Delete if Exists)
Message #1 by "Stuart Shay" <sshay@j...> on Fri, 5 Apr 2002 19:12:46
|
|
Hello All:
I want to rename file using the file system object.
I am able to rename the file, if the file with the new name does not yet
exist.
The problem is if the file exists I want to delete that file with the new
name, then rename the old file to new file name.
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(NewFileName) Then
' Error in this part
' objFSO.DeleteFile("NewFileName")
' objFSO.MoveFile OldFileName,NewFileName
Else
objFSO.MoveFile OldFileName,NewFileName
End If
Thanks
Stuart
Message #2 by Jack_Speranza <jsperanza@g...> on Fri, 5 Apr 2002 14:13:46 -0500
|
|
Assuming the term "NewFileName" is a variable, then you're enclosing it in
quotes on the delete file command is probably causing the problem...
If objFSO.FileExists(NewFileName) Then
' Error in this part
' objFSO.DeleteFile("NewFileName")
^^^^^^^^^^^^
' objFSO.MoveFile OldFileName,NewFileName
|
|
 |