powershell - Rename files to match filenames in another folder -


i have 2 directories.

d:\test\get\f  d:\test\set\f 

inside get folder , set folders there equal amount of files. files in set same (it's common image file duplicated multiple times match number of files in set folder).

my question is, how rename files in set folder same in get folder?

e.g.:

before

get folder

apple.jpg mango.jpg lychee.jpg 

set folder

123.jpg 12!.jpg asdasd.jpg 

after

get folder

apple.jpg mango.jpg lychee.jpg 

set folder

apple.jpg mango.jpg lychee.jpg 

a simple example unoptimised , assumes best case. shows basic steps of iterating through files in path, getting file names , renaming files.

$names = @() $getpath = "c:\temp\get" $setpath = "c:\temp\set" get-childitem $getpath |     foreach-object{     $names += $_ } $i = 0 get-childitem $setpath | foreach-object{     rename-item -path $_.fullname -newname $names[$i]     $i++ } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -