Solved

how to use xcopy from within vbscript

Posted on 2007-04-02
3
3,264 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:novice12
[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
  • Learn & ask questions
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18839608
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
0
 

Author Comment

by:novice12
ID: 18839872
Great!!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18839882
Happy to help - thanx for the grade! :^)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question