Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rename a file using VBScript?

Tags:

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

like image 674
user505210 Avatar asked Jul 15 '13 17:07

user505210


2 Answers

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"
like image 64
Roman R. Avatar answered Oct 10 '22 23:10

Roman R.


I see only one reason your code to not work, missed quote after file name string:

VBScript:

FSO.GetFile("MyFile.txt[missed_quote_here]).Name = "Hello.txt"
like image 43
seeker Avatar answered Oct 10 '22 22:10

seeker