Solved

Script for copying files listed in a txt file

Posted on 2014-01-09
5
294 Views
Last Modified: 2014-01-15
Hi All,

I'm in need of a script or batch file to copy files listed in a txt file. The files listed use many different paths but I want them copied to the same path, just on a different drive.

example of files2copy.txt:

X:\AW\FAR\P946.PDF
X:\AW\FAR\SupFar.PDF
X:\AW\FAR\TIP.DOC
X:\AW\PFP\ANALYSIS.MDB
X:\AW\PFP\COLLEGE.MDB
X:\EASY\DATA\A4G.DER
X:\EASY\DATA\ADRDATX.CER
X:\EASY\DATA\ADRDATX.DER

Again, I would need these files copied from source x:\<path> to the same path on destination  T:\<path> (both local drives) . These files already exist on destination T:\ <path> and should be overwritten from the ones copied from X drive.

Did I lose anybody??

Thanks in advance.
0
Comment
Question by:ITMan64
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39769907
Try this.  It should SHOW you the copy commands it would do on the screen.  Remove the word ECHO and it will run them instead.

hth

Steve

@echo off
set FileList=files2copy.txt
Set DestDir=T:

for /f "tokens=1* delims=:" %%A in ('type "%filelist%"') do (
  ECHO COPY /Y "%%~A:%%~B" "%DestDir%%%~B"
)

Open in new window

0
 

Author Comment

by:ITMan64
ID: 39770030
Steve,

I think you nailed it! I tried a sample of files and it looks like it would work as I needed.
Thanks so much! I will post back if I run into any problems.

Thanks Again,

-Rob
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39770293
No problem, can always add some logging and the like too if needed, i.e. if source or det file doesnt exist or the copy fails etc.

Steve
0
 

Author Comment

by:ITMan64
ID: 39781625
Steve,

Those additional functions would be a great help if possible. Thanks.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39781881
OK you can start doing more with things like this... if you want anything specific ask a question and link back to this one and someone will pickup.  I haven't tested below so apologies if any typos.

Steve

@echo off
set FileList=files2copy.txt
Set Log="c:\somedir\log.txt"
Set DestDir=T:

for /f "tokens=1* delims=:" %%A in ('type "%filelist%"') do (
  If exist "%DestDir%%%~B" echo "%DestDir%%%~B" already exists >> %LOG%
  If not exist "%%~A:%%~B" (
    echo "%%~A:%%~B" does not exist in source >> %log%
  ) ELSE (
    COPY /Y "%%~A:%%~B" "%DestDir%%%~B"
    if errorlevel 1 echo Error %errorlevel% copying "%%~A:%%~B" >> %log%
  )
)

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

Suggested Solutions

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

11 Experts available now in Live!

Get 1:1 Help Now