Solved

Locate and copy from file

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

23 Experts available now in Live!

Get 1:1 Help Now