JJ2357
JJ2357

Reputation: 153

Bulk copy and rename using lookup file using Powershell

I have a directory that contains image files named by "parent", like this:

I have a lookup file that matches each parent to its children.

aaa.jpg , 111.jpg
aaa.jpg , 222.jpg
aaa.jpg , 333.jpg
bbb.jpg , 444.jpg
bbb.jpg , 555.jpg
bbb.jpg , 666.jpg

I need to copy each parent file and rename it as the name of each associated child. That is, I need to generate files:

I'm trying to use the solution posted here: Rename Files & Folders Keywords - Using a CSV Look Up File, however after the parent is renamed to the first child, further renaming can't happen. Any ideas on how to copy, then rename so that all children can be renamed?

Thanks

Upvotes: 0

Views: 277

Answers (1)

TessellatingHeckler
TessellatingHeckler

Reputation: 29048

Any ideas on how to copy, then rename so that all children can be renamed?

by using copy-item instead of rename-item.

Assuming the CSV has no headers:

Import-Csv lookup.csv -Headers Parent, Child | 
    ForEach-Object { 

        Copy-Item -LiteralPath "c:\temp\$($_.Parent)" -Destination "c:\temp\$($_.Child)"

    }

Upvotes: 0

Related Questions