1
votes

I have a HTA to do some tasks, this sub is for manipulating some local directories. When I run this line:

oShell.run "rename ""C:\DSS\Scanbay\Data"" ""DataX"""

it doesnt work, naturally I have defined oShell ect...

When I run this line as a batch file:

rename "C:\DSS\Scanbay\Data" "DataX"

it works fine!

I cannot figure out why the vbs returns file not found error, any help please?

1
Try oShell.Run "cmd /c rename ""C:\DSS\Scanbay\Data"" ""DataX"" instead. You might find SS64 on VBScript '.Run' useful. The .ShellExecute method might also be of interest.Jeff Zeitlin
The RENAME command is an internal cmd.exe command so if you are not explicitly within a batch file or at a cmd prompt you will need to specifiy the use of CMD /C within your vbscript as @JeffZeitlin has pointed out.Squashman

1 Answers

3
votes

As others have already pointed out, rename is a CMD-builtin command, not an external program that you can invoke directly. You can invoke it via CMD, though:

oShell.Run "cmd /c rename ""C:\DSS\Scanbay\Data"" ""DataX"""

With that said, a better approach to renaming files or folders would be using the FileSystemObject:

Set fso = CreateObject("Scripting.FileSystemObject")

Set d = fso.GetFolder("C:\DSS\Scanbay\Data")
d.Name = "DataX"