Solved

Need batch script to copy multiple files for Windows

Posted on 2016-09-20
4
44 Views
Last Modified: 2016-09-22
I want to copy the following files below with a batch script that I can schedule using task scheduler. I want to replace with new files with every copy. If possible, even if the file is locked. Xcopy? Any good batch scripts?

ARCPMA01.CDX
ARCPMA01.DBF
ARCUST01.CDX
ARCUST01.DBF
arcust01.FPT
ARIALT01.CDX
ARIALT01.DBF
ARIALT01.FPT
ARIDET01.CDX
ARIDET01.DBF
ARIDET01.FPT
ARINVT01.CDX
ARINVT01.DBF
ARINVT01.FPT
ARINVT02.CDX
ARINVT02.DBF
ARINVT02.FPT
POMAST01.CDX
POMAST01.DBF
POMAST01.FPT
POTRAN01.CDX
POTRAN01.DBF
POTRAN01.FPT
POYMST01.CDX
POYMST01.DBF
POYMST01.FPT
POYTRN01.CDX
POYTRN01.DBF
POYTRN01.FPT
WOLABO01.CDX
WOLABO01.DBF
WOMAST01.CDX
womast01.DBF
womast01.FPT
WOTRAN01.CDX
WOTRAN01.DBF
wotran01.FPT
WOYTRN01.CDX
WOYTRN01.DBF
woytrn01.FPT
0
Comment
Question by:maximus1974
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
Do you know power shell commands ? It is one of good option.
0
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
Do you want to copy just those files listed? Or, do you want all the files of a certain folder?

To copy just those files listed...
- Make a file named FilesToCopy.txt. In it, put each filename you listed on a separate line
- Make this file CopyFiles.bat with this code.
- Adjust SourceDir, and TargetDir value per your need:

set SourceDir=c:\sourcefolder
set TargetDir=c:\targetfolder
for /f "tokens=*" %%a in ('type "C:\local\FilesToCopy.txt"') do (
  echo xcopy /z /y "%%a" "%TargetDir%"
)

Open in new window


- When you have confirmed that it works manually, you can add a scheduled task Action that runs CopyFiles.bat
0
 

Author Comment

by:maximus1974
Comment Utility
Thank you but it is not working. I attached a screenshot. I run the batch from a command prompt but it is not copying the files.
Capture.PNG
0
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
Comment Utility
Apologies.  I forgot to mention it wa in test mode. Try this instead....

set SourceDir=w:\
set TargetDir=g:\qav
for /f "tokens=*" %%a in ('type "C:\batch\FilesToCopy.txt"') do (
  echo xcopy /z /y "%SourceDir%%%a" "%TargetDir%"
)

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now