hjalp
hjalp

Reputation: 1

Choose where the number increments starts in PowerShell

dir -exclude "newname_" | %{Rename-Item $_ -NewName ('newname_{0}.pdf' -f $nr++)}

This gives me

newname_1.pdf, newname_2.pdf, newname_3.pdf

etc

but what if I want it to start on another number:

newname_174.pdf, newname_175.pdf etc

Upvotes: 0

Views: 123

Answers (1)

pinkfloydx33
pinkfloydx33

Reputation: 12749

Easy! Just declare your counter before the rest of your command and initialize it with the value you want to start at:

$nr=174
dir -exclude "newname_" | %{Rename-Item $_ -NewName ('newname_{0}.pdf' -f $nr++)}

You can do it all in a single line by separating the two expressions with a semicolon

$nr=174; dir -exclude "newname_" | %{Rename-Item $_ -NewName ('newname_{0}.pdf' -f $nr++)}

Upvotes: 1

Related Questions