p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

proasp_howto thread: [proasp_howto] rename file

Message #1 by adi@p... on 29 Mar 2001 09:51:02 -0000

this is from 4guys web site

Question: How can I rename a file on my Web site through an ASP page?
[Print this FAQ]


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"), _

Set objFSO = Nothing

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

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.

-----Original Message-----
From: adi@p... [mailto:adi@p...]
Sent: Thursday, March 29, 2001 4:51 AM
To: How To
Subject: [proasp_howto] rename file

Could somebody help me ?

I use aspsmartupload component to upload a file. After the file has been

in a directory, I want to rename the file. How could I do that ? File

object doesn't provide a method or properties to change file's name.


  Return to Index