27

I need to run a command to copy a file from one location to another through Command Prompt using a vbs file. this is what I have however it keeps throwing an error at me.

'Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /C copy "S:Claims\Sound.wav" "C:\WINDOWS\Media\Sound.wav"
Set oShell = Nothing'

The error i get is:

'Script: C:\******\command.vbs
Char: 30
Error: Expected end of statement
Code: 80040401

Source: Microsoft VBScript compilation error'

Please help :)

2 Answers 2

45

The problem is on this line:

oShell.run "cmd.exe /C copy "S:Claims\Sound.wav" "C:\WINDOWS\Media\Sound.wav"

Your first quote next to "S:Claims" ends the string; you need to escape the quotes around your files with a second quote, like this:

oShell.run "cmd.exe /C copy ""S:\Claims\Sound.wav"" ""C:\WINDOWS\Media\Sound.wav"" "

You also have a typo in S:Claims\Sound.wav, should be S:\Claims\Sound.wav.

I also assume the apostrophe before Dim oShell and after Set oShell = Nothing are typos as well.

4
  • Hello, Thank you for your response, that makes sense. Yeah the apostrophe's were typos. Works a treat! :) Apr 19, 2013 at 10:12
  • s:claims\sound.wav is valid (file sound.wav under claims folder in current working folder on S drive) where S:\claims specify that claims folder is on the root (and maybe the same as s:claims) Jan 28, 2014 at 13:09
  • 2
    Hi user1590368, Could you please mark this solution as the right answer?
    – Navin
    Jan 29, 2015 at 23:06
  • I would rather do this (not sure if works) than what you or user1590368 is doing.
    – zulc22
    Mar 3, 2015 at 4:48
4
Set oShell = CreateObject ("WScript.Shell") 
oShell.run "cmd.exe /C copy ""S:Claims\Sound.wav"" ""C:\WINDOWS\Media\Sound.wav"" "
2
  • if the file path doesn't contain blank space, you dont have to put qoute around filename. May 16, 2021 at 11:55
  • 2
    You also missed the S:Claims typo. Aug 14, 2022 at 19:00

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.