how to use xcopy from within vbscript

novice12
novice12 used Ask the Experts™
on
I need to do this:
Copy all files that end with "_15.dat" from path : "c:\local_data\" to a new network drive "T:\remote_data\"
Can I use xcopy to accompish this. And how can I write to the event-viewer when an error occurs while copying the files.

I am using VBscript.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
Commented:
Hello novice12,

Sure, you can use xcopy...
Make an object reference to the shell (Set objShell=CreateObject("Wscript.Shell") and then use the Run method (objShell.Run "Xcopy <source> <target>"
But I would probably go for pure vbscripting rather than using the shell..

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolder:Set objFolder=objFSO.GetFolder("C:\local_data\")
For Each file In objFolder.Files
  If Right(file.Name,7) = "_15.dat" Then objFSO.CopyFile file.path, "T:\remote_data\"
Next


~sirbounty

Author

Commented:
Great!!
Top Expert 2007

Commented:
Happy to help - thanx for the grade! :^)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial