I have below files in folder with a same name. Only the extensions are different. All files are valid jpg but with the wrong extension.
How to rename them with extension as .jpg, with a different prefix?
ren *.* *.jpg ----> Is not working for me as they all are having same prefix
CodePudding user response:
This should work for you:
Clear-Host
$directoryPath = "C:\directory\with\images"
#Getting all files with "1.*" from $directoryPath
$foldercontent = Get-ChildItem -Path $directoryPath -Filter "1.*" | Where-Object { ! $_.PSIsContainer }
foreach($item in $foldercontent) {
Move-Item -Path $item.FullName -Destination "$directoryPath\image$($item.Extension).jpg"
}
File names will be:
image.J84.jpg
image.J85.jpg
CodePudding user response:
You could use the ForFiles utility for such a task, in the Command Prompt, PowerShell Prompt, or from a batch file.
forfiles /p "C:\directory\with\images" /m "1.*" /c "cmd /c ren @file [email protected]"

