I have files like below:


And I having the folder names:


I want to move the two files with the same name to the same folder.

How can I do this?

  • 1
    Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?. – DavidPostill Mar 23 '17 at 9:56
  • 1
    Store L-Shaped_Single_Hole_(Elliptical) and DC_GEN_ENT_Billboard into 2 variables and then use a condition on those to filter them. – Overmind Mar 23 '17 at 10:37
  • 1
    Go the other way around, search files matching foldername* and move them. – LotPings Mar 23 '17 at 12:57

I used a root folder of C:\temp7, so you'll have to change that to wherever your folders are. This is a powershell script file. Open a notepad, paste this code, modify what you need, save as a .ps1 file and run it.

# Set source folder and destination folders
$sourceFolder = "C:\temp7"
$destinationFolder1 = "C:\temp7\L-Shaped_Single_Hole_(Elliptical)"
$destinationFolder2 = "C:\temp7\DC_GEN_ENT_Billboard"

# Find all files matching "L-Shaped" in and move into Lshaped folder
Get-ChildItem -Path $sourceFolder -Filter L-Shaped* | ForEach-Object { move-item -Path $_.FullName -Destination $destinationFolder1 }

# Find all files matching "DC_GEN" in and move into DC_GEN folder
Get-ChildItem -Path $sourceFolder -Filter DC_GEN* | ForEach-Object { move-item -Path $_.FullName -Destination $destinationFolder2 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.