Search code examples
vbscript

How do I rename a file using VBScript?


I am trying to rename a file and was using the below code but it does not seem to work. Can someone please tell me why? What is the correct way to rename a file from VBScript?

FSO.GetFile("MyFile.txt).Name = "Hello.txt"

I am using this thread for reference: Rename files without copying in same folder


Solution

  • You can rename the file using FSO by moving it: MoveFile Method.

    Dim Fso
    Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
    Fso.MoveFile "A.txt", "B.txt"