Solved

Script for copying files listed in a txt file

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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