powershell - Increment using 2 digit number -
i have following code append incremental number beggining of each filename. how can make start 01 instead of 1.
$files = get-childitem "c:\test" $i = 1 foreach ($file in $files) { $newname = "$i" + $file rename-item $($file.fullname) $newname $i++ }
several ways this, use -f (format) operator.
here's how i'd write in pipeline:
get-childitem "c:\test" | foreach-object -begin { $i=1 } { rename-item $_ -newname ("{0:d2}{1}" -f ($i++, $_.name)) }
p.s. forget it's possible eliminate foreach-object using delay-bind scriptblock. comes in particularly handy rename-item:
$i = 1 get-childitem "c:\test" | rename-item -newname {"{0:d2}{1}" -f ($i++, $_.name)}
Comments
Post a Comment