Solved

how to use xcopy from within vbscript

Posted on 2007-04-02
3
3,251 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now