?
Solved

Script for copying files listed in a txt file

Posted on 2014-01-09
5
Medium Priority
?
304 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
[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
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

764 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