Skip to main content
added 273 characters in body
Source Link
Cpt.Whale
  • 8.5k
  • 2
  • 17
  • 33

Here's an example in powershell:

$src = "C:\Source"
$dst = "C:\Destination"

# get all the files including in subfolders, without including directory names
$files = Get-ChildItem $src -Recurse -File

# group files by name, withoutand extension
foreachonly ($groupthe inones (with matches
$grouped = $files | Group-Object -Property BaseName) | Where Count -GE 2
foreach ($group in $grouped){

  # copy each group of files to a single folder
  $group.Group.Fullname | Copy-Item -Destination (Join-Path $dst $group.Name)

}
 

ThisFor example, the files in this source folder:

C:\Source\Pictures\RAW\
  FileOne.ARW
  FileTwo.ARW
  FileThree.ARW
C:\Source\Pictures\Compressed\
  FileOne.JPG
  FileTwo.JPG

will end upget copied to the destination like:

C:\Destination\FileOne\
  FileOne.jpgARW
  FileOne.txtJPG
C:\Destination\FileTwo\
  FileTwo.jpgARW
  FileTwo.pdfJPG

Here's an example in powershell:

$src = "C:\Source"
$dst = "C:\Destination"

# get all the files including in subfolders, without including directory names
$files = Get-ChildItem $src -Recurse -File

# group files by name without extension
foreach ($group in ($files | Group-Object -Property BaseName)){

  # copy each group of files to a single folder
  $group.Group.Fullname | Copy-Item -Destination (Join-Path $dst $group.Name)

}

This will end up like:

C:\Destination\FileOne\
  FileOne.jpg
  FileOne.txt
C:\Destination\FileTwo\
  FileTwo.jpg
  FileTwo.pdf

Here's an example in powershell:

$src = "C:\Source"
$dst = "C:\Destination"

# get all the files including in subfolders, without including directory names
$files = Get-ChildItem $src -Recurse -File

# group files by name, and only the ones with matches
$grouped = $files | Group-Object -Property BaseName | Where Count -GE 2
foreach ($group in $grouped){

  # copy each group of files to a single folder
  $group.Group.Fullname | Copy-Item -Destination (Join-Path $dst $group.Name)

}
 

For example, the files in this source folder:

C:\Source\Pictures\RAW\
  FileOne.ARW
  FileTwo.ARW
  FileThree.ARW
C:\Source\Pictures\Compressed\
  FileOne.JPG
  FileTwo.JPG

will get copied to the destination like:

C:\Destination\FileOne\
  FileOne.ARW
  FileOne.JPG
C:\Destination\FileTwo\
  FileTwo.ARW
  FileTwo.JPG
Source Link
Cpt.Whale
  • 8.5k
  • 2
  • 17
  • 33

Here's an example in powershell:

$src = "C:\Source"
$dst = "C:\Destination"

# get all the files including in subfolders, without including directory names
$files = Get-ChildItem $src -Recurse -File

# group files by name without extension
foreach ($group in ($files | Group-Object -Property BaseName)){

  # copy each group of files to a single folder
  $group.Group.Fullname | Copy-Item -Destination (Join-Path $dst $group.Name)

}

This will end up like:

C:\Destination\FileOne\
  FileOne.jpg
  FileOne.txt
C:\Destination\FileTwo\
  FileTwo.jpg
  FileTwo.pdf