ASPFAQs.com
Your source for ASP-related frequently asked questions and answers!


4GuysFromRolla.com : ASP FAQS : FileSystemObject

Question: How can I rename a file on my Web site through an ASP page?

Answer: Unfortunately the FileSystemObject doesn't contain a Rename method; it does, however, have a method that can be used as a substitute for Rename: MoveFile. MoveFile accepts two parameters: the physical path to an existing file and the physical path to where you want to move the file. To rename a file, all we have to do is alter the filename from the first parameter to the second. For example, if we wanted to rename Foo.asp to Bar.asp, we could use the following code:

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

objFSO.MoveFile Server.MapPath("/someDir/Foo.asp"), _
                Server.MapPath("/someDir/Bar.asp")

Set objFSO = Nothing

For more information on Server.MapPath be sure to read: Using Server.MapPath!

And there you have it! Renaming a file is as simple as moving it to the same directory, but changing the filename! For more information on the MoveFile method, be sure to read the technical docs.


FAQ posted by Scott Mitchell at 9/28/2000 2:42:12 PM to the FileSystemObject category. This FAQ has been viewed 65,425 times.


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers