[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# I want to make a copying program for vbs

Posted on 2016-10-23
Medium Priority
66 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
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
1 Comment

LVL 58

Accepted Solution

Bill Prew earned 2000 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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
###### Suggested Courses
Course of the Month13 days, 11 hours left to enroll