0

I am having a hard time describing the problem and I can't find the solution anywhere so here is an example

SourceFolder\ProjectA\Legal\ContractA.txt
SourceFolder\ProjectB\Legal\ContractB.txt
SourceFolder\ProjectC\Legal\ContractC.txt
SourceFolder\ProjectD\Legal\ContractD.txt
etc..

I need to copy the contractletter.txt file from hundreds of these Projectletter folders to a single location such as this:

DestinationFolder\ContractA.txt
DestinationFolder\ContractB.txt
DestinationFolder\ContractC.txt
DestinationFolder\ContractD.txt
etc..

Is there a PowerShell command that will do it?

6
  • gci SourceFolder\Contract* -rec | % {copy-item $_ -destination "DestinationFolder\$($_.name)"} might do but you would overwrite identical filenames Oct 28, 2021 at 14:25
  • I think this would be ok if the path up to the Contract.txt files would be the same but the Project folder names are all different
    – Artrelay
    Oct 28, 2021 at 14:36
  • If the filenames are all different, the oneliner could suffice. Add a -whatif just before the } to do a dry run. Oct 28, 2021 at 14:38
  • It's not just the files that are different it is also the folder before, the ProjectA,B,C and D folders
    – Artrelay
    Oct 28, 2021 at 14:49
  • 1
    Great, that did it, thanks for your help
    – Artrelay
    Oct 28, 2021 at 15:07

0

You must log in to answer this question.

Browse other questions tagged .