Solved

Locate and copy from file

Posted on 2014-09-30
4
57 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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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