Solved

Locate and copy from file

Posted on 2014-09-30
4
60 Views
Last Modified: 2015-02-04
Consider the following:

Source directory with 5000 sub folders, each with hundreds of unique file names
Text file file with 1000 only unique file names - no path

I must copy only the files in the text file (remember no path) from the source while replicating the original path to a new destination drive

What would be an efficient method in powershell or DOS to read from the text file and copy the resulting files into a new source directory retaining the relative path in the destination?
0
Comment
Question by:avatech
[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
4 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40353025
$fpath = "F:"
$dest = "C:\destination"
gc .\files.txt | % {$named = $_;gci $fpath -recurse | ? {$_.name -eq $named } | % {$forig = $_.fullname;$nufile = $forig -replace $fpath, $dest;$nuname = ($_ | select -ExpandProperty DirectoryName) -replace $fpath, $dest ; if (!(Test-Path $nuname)) {New-Item -Path $nuname -ItemType Directory; "Directory created....."};Copy-Item $forig $nufile}}

Open in new window

0
 
LVL 4

Author Comment

by:avatech
ID: 40373632
Testing this weekend it's been a low priority.
0

Featured Post

Independent Software Vendors: 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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

691 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