Solved

Script for copying files listed in a txt file

Posted on 2014-01-09
5
298 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
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 …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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