Solved

how to use xcopy from within vbscript

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…

837 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