Question

Does anyone know much about powershell?

I have about 3k files i want to edit the name of.. for example

90_12200.jpg

to

12200p.jpg

anyone know?

Was it helpful?

Solution

You can use Get-Child item with recursive option to load all the jpg files and rename it using Rename-item command.

Get-ChildItem -r -path "C:\test" *.jpg | % { if(!$_.PSIsContainer -and $_.Name.Contains('_')) {Rename-item $_.FullName ( $_.BaseName.Split('_')[1] +"p" + $_.Extension) } }

OTHER TIPS

Generate some test files first:

0..4 | % { set-content 90_1220$_.jpg "" }
# Output
90_12200.jpg
90_12201.jpg
90_12202.jpg
90_12203.jpg
90_12204.jpg

Then list the files, pass to foreach and rename. $($_.BaseName.Replace("90_", "")+"p"+$_.Extension) will take the base name, remove 90_, add letter p and file's extension.

gci 90_*.jpg | % { Move-Item $_ $($_.BaseName.Replace("90_", "")+"p"+$_.Extension) }
gci
# Output
12200p.jpg
12201p.jpg
12202p.jpg
12203p.jpg
12204p.jpg
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top