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
Solved

Locate and copy from file

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Know what services you can and cannot, should and should not combine on your server.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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 …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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