0

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?

2
  • What are the exact renaming rules? Apparently you wish to remove "90_" and add "p" to the name. Is this all you need? Any exceptions? Commented Jul 10, 2013 at 9:39
  • yes that's all that needs to be done really. Commented Jul 10, 2013 at 9:50

2 Answers 2

1

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) } }
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.