Solved

Locate and copy from file

Posted on 2014-09-30
4
54 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
4 Comments
 
LVL 28

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now