Library code snippets

Rename files using the FileSystemObject

You may have noticed that the FileSystemObject doesn't have a Rename method anywhere in its object model. This does not, however, mean that you can't rename a file. The answer lies in the realization that you can use the MoveFile method, specifying two different file names in the same directory. A sample of this technique is shown below:

<%
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.MoveFile "d:\dummytest.txt", "d:\dummytest2.txt"
%>

Comments

  1. 18 Apr 2007 at 02:50

    Hey..

    I was just wondering, with renaming a file using filessystemobject how would you go about overwriting the file if it exists. I'm sure i've read it somewhere and simply can't seem to remember it.

    Any help would be great.

    Thanks

  2. 27 Nov 2002 at 00:20
    I am very new to this world but was looking for a method copy files. I have then noticed this code under the subject Rename a file using the Filesystemobject. I though that it may work with Copyfile aswell and guess what it does work very well. So for those who may want to know here is the code to copy a file using the FilesystemObject.

    <%
      Dim fso
      Set fso = CreateObject("Scripting.FileSystemObject")
      fso.CopyFile "c:dummytest.txt", "c:dummytest2.txt"
    %>
  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Rename files using the FileSystemObject.

Leave a comment

Sign in or Join us (it's free).

ElementK Journals
AddThis

Related discussion

Related podcasts

  • Scott Guthrie

    Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.

Events coming up

Want to stay in touch with what's going on? Follow us on twitter!