batch Script file for move files to the specific folder

batch Script file for move files to the specific folder

I have files like below:

L-Shaped_Single_Hole_(Elliptical)_10.jpg
L-Shaped_Single_Hole_(Elliptical)_11.jpg
DC_GEN_ENT_Billboard_10.jpg
DC_GEN_ENT_Billboard_11.jpg

And I having the folder names:

L-Shaped_Single_Hole_(Elliptical)
DC_GEN_ENT_Billboard.

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

How can I do this?

答案1

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 }

相关内容