Solved

# I want to make a copying program for vbs

Posted on 2016-10-23
36 Views
I have got this far and I am stuck. I want to make a program which copies itself to another location, but when it discovers its location, it doesn't add its own filename to the variable, How do you add the file name onto the end of the variable?
My code is here:

Option Explicit
Dim wshShell
Dim oFSO
Dim sScriptDir
Dim sTargetFolder
Dim sCmd
set wshShell  = CreateObject("Wscript.Shell")

Set oFSO = CreateObject("Scripting.FileSystemObject")

sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
msgBox "Location," & sScriptDir
sTargetFolder = "C:\Users\Arion\Documents\Environment\Test"

sCmd = "%comspec% /c copy """ & sScriptDir & """ """ & sTargetFolder & """ /Y"

==================================================EDIT:

This doesn't work either, shame, It should do, I can see why though, It recognises \wippre-alpha.vbs on the end as a string.

Option Explicit
Dim wshShell
Dim oFSO
Dim sScriptDir
Dim sTargetFolder
Dim sCmd
Dim sScriptDirfn
set wshShell  = CreateObject("Wscript.Shell")

Set oFSO = CreateObject("Scripting.FileSystemObject")

sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
sScriptDirfn = sScriptDir & "\wippre-alpha.vbs"
msgBox "Location," & sScriptDirfn
sTargetFolder = "C:\Users\Arion\Documents\Environment\Test"

sCmd = "%comspec% /c copy """ & sScriptDirfn & """ """ & sTargetFolder & """ /Y"
0
Question by:Arion Sejdia
1 Comment

LVL 52

Accepted Solution

Bill Prew earned 500 total points
ID: 41856273
This seemed to work for me, and copied the VBS file to the target folder.

Option Explicit

Dim objShell, strCmd, strTargetFolder

strTargetFolder = "B:\ee\EE28978298\dest"

Set objShell = CreateObject("WScript.Shell")

strCmd = "%comspec% /c copy """ & WScript.ScriptFullName & """ """ & strTargetFolder & """ /Y"
objShell.Run strCmd

~bp
1

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Copy XML file and strip off certain elements 4 38
Show hidden user account 7 55
Script is being strange 8 63
Running Access application from Task Scheduler 6 32
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…