powershell - Adding an auto-incrementing number to a file name string -


i powershell script modify name of file increment number every time.

this file name: abc-0.2.0.1-snapshot-barista.zip. want write syntax increment every time mentioned below:

 abc-0.2.0.2-snapshot-barista.zip abc-0.2.0.3-snapshot-barista.zip abc-0.2.0.4-snapshot-barista.zip abc-0.2.0.5-snapshot-barista.zip abc-0.2.0.6-snapshot-barista.zip abc-0.2.0.7-snapshot-barista.zip abc-0.2.0.8-snapshot-barista.zip abc-0.2.0.9-snapshot-barista.zip abc-0.2.0.10-snapshot-barista.zip abc-0.2.0.11-snapshot-barista.zip 

and on …

use regular expression replacement callback function:

$name = 'abc-0.2.0.4-snapshot-barista.zip'  [regex]$re = '(.*?\.)(\d+)(-snapshot-.*\.zip)' $cb = {     $a, $b, $c = $args[0].groups[1..3].value     '{0}{1}{2}' -f $a, ([int]$b+1), $c }  $re.replace($name, $cb) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -