Earlier quoted context omitted.
ls | % {rename-item $_ -newname $('myfile_' + ($_.BaseName -replace '\D') + '.md' )} No need to remember anything.
? I would be much more likely to remeber ls | renamer than figure out how to write such a command.
Nope.
> to remeber
That's the point, you don't need to remember anything, it would come naturally after a day of tinkering with PS/pwsh.
You just write it for your current needs.
This example was just a quick one-liner, it's very simple:
ls | % { # get the file list, cycle for each item
rename-item # obvious usage: rename-item oldname newname
$_ # pretty obvious, the source - place the loop variable here ie file name
-newname # explicit calling for a parameter name, isn't really needed
$( # subroutine start or eval if you prefer, to construct the new file name:
# 'text' + (take property basename from the file and regex it) + 'text'
'myfile_' + ($_.BaseName -replace '\D') + '.md'
) # subroutine end
} # cycle end.
It could be simplified (in this example) to this: ls | % {
$a = 'myfile_' + ($_ -replace '\D') + '.md'
rename-item $_ $a
}
which could be even written as a one-liner if you prefer it right now, just add a semicolon after `$a = ...` ls | % {$a = 'myfile_' + ($_ -replace '\D') + '.md'; rename-item $_ $a }