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


4GuysFromRolla.com : ASP FAQS : FileSystemObject

Question: How can I rename a directory on my Web server?

Answer: In a previous FAQ - How can I rename a file on my Web site through an ASP page? - we looked at how to rename a file on a Web server's filesystem. To accomplish this, though, you had to resort to clever programming, since the FileSystemObject does include any sort of Rename method. In order to rename a file, you need to use the MoveFile method like so:

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

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

Set objFSO = Nothing

which will rename the file on your Web site /someDir/Foo.asp to /someDir/Bar.asp.

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

To rename a directory on a Web server, we must use the same approach using the MoveDirectory method (seeing as there's no RenameDirectory method available). So, if you have a directory on your Web server with the physical path C:\Foo and you wished to rename it to C:\Bar, you could use the following code:

'Create an instance of the FileSystemObject
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

objFSO.MoveFolder "C:\Foo", "C:\Bar"

That's it! At this point the directory Foo would be renamed Bar. For more information on manipulating the Web server's filesystem using the FileSystemObject be sure to read the technical docs. Also, be sure to check out the FileSystemObject FAQ category!

Happy Programming!


FAQ posted by Scott Mitchell at 8/14/2001 12:24:18 PM to the FileSystemObject category. This FAQ has been viewed 54,063 times.


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