简体   繁体   中英

Powershell - How copy list of files to destination

I have a textfile (myfile.txt) that contains the source/destination of files to copy. For example....

c:\work\test1.txt \\server.usa.svr.com\sites\mysite\ztest1.txt
c:\work\test2.txt \\server.usa.svr.com\sites\mysite\ztest2.txt
c:\work\test3.txt \\server.usa.svr.com\sites\mysite\ztest3.txt
c:\work\test4.txt \\server.usa.svr.com\sites\mysite\ztest4.txt
c:\work\test5.txt \\server.usa.svr.com\sites\mysite\ztest5.txt
c:\work\test6.txt \\server.usa.svr.com\sites\mysite\ztest6.txt

Using powershell how can I open the file and copy from source to destination, for each file. Also, giving a status if error or success?

Thanks!

If you don't have spaces in file names (or they are properly quoted) you can try the following:

Import-Csv myfile.txt -Delimiter ' ' -Header Path,Destination | Copy-Item

You can pipe to Copy-Item -WhatIf first to see whether it's doing the right thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM