• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 833
  • Last Modified:

Pass Parameters to a VB Script to copy file

I have a batch file to copy files to the local desktop path that I call from my application (MAS200)....but the batch can't pass results back to the user.  So, can someone give me a VB Script that I can pass parameters ie., ....

VBScriptName.vbs <PathToSourcefile> <DestinationPath>

I want to give the user a MsgBox indicating the copy results.

Thanks
Craig

0
oceansupport
Asked:
oceansupport
  • 3
  • 2
  • 2
1 Solution
 
sr75Commented:
Here you go:
strfile = "C:\sometextfile.txt"
 
set objFSO = CreateObject("Scripting.FileSystemObject")
set rFile = objFSO.OpenTextFile(strFile)
Do until rFile.AtEndOfStream
	rLine = rFile.ReadLine
	If rLine <>"" then
		results = results & rLine
	End If
End
 
rFile.close
wscript.echo results

Open in new window

0
 
sr75Commented:
whoops!!  should be a DO....LOOP  not a  DO....END
0
 
oceansupportAuthor Commented:
Will this work with this concept?
CopyScript.vbs <Sourcepath> <destinationpath>

Thanks
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sr75Commented:
No it will not and I am not sure that you can pass parameters to a vbscript, but you can create a vbscript and run it from within a dos batch script.  So you can pass the parameters at the time of creation.  Just use the script I have provided you as a template of what to have your batch script create.
0
 
RobSampsonCommented:
Hi, you can run the following like this:

wscript test.vbs /Source:"C:\dsk.txt" /Destination:"C:\Temp\Temp\Test Script"

and this is the code in test.vbs

'=================
If WScript.Arguments.Count <> 2 Then
      MsgBox "You must pass two arguments to this script." & VbCrLf & _
            "Usage: wscript.exe CopyFile.vbs /Source:""<sourcepath>"" /Destination:""<destinationpath>""", vbOKOnly, "Error"
      WScript.Quit
End If
strSource = WScript.Arguments.Named("Source")
strDestination = WScript.Arguments.Named("Destination")
If Right(strDesination, 1) <> "\" Then strDestination = strDestination & "\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strSource) = False Then
      MsgBox "Could not find source file: " & strSource, vbOKOnly, "Error"
      WScript.Quit
End If
If objFSO.FolderExists(strDestination) = False Then
      MsgBox "Could not find destination folder: " & strDestination, vbOKOnly, "Error"
      WScript.Quit
End If
On Error Resume Next
objFSO.CopyFile strSource, strDestination, True
If Err.Number = 0 Then
      On Error GoTo 0
      MsgBox "File copied successfully.", vbOKOnly, "Success"
Else
      Err.Clear
      On Error GoTo 0
      MsgBox "File copy failed.", vbOKOnly, "Error"
End If
'=================

Regards,

Rob.
0
 
oceansupportAuthor Commented:
Thank you!!!!
0
 
RobSampsonCommented:
No problem.  Thanks for the grade.

Regards,

Rob.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now