I'd like to batch rename files in a folder, prefixing the each filename line counts and "_" into the new names. example
a.txt
b.txt
c.txt
d.txt
to
1000_a.txt
32_b.txt
199_c.txt
8_d.txt
Bonus: pad the line counts with leading zeroes to
1000_a.txt
0032_b.txt
0199_c.txt
0008_d.txt
what i tried: from command that add suffix
Dir | Rename-Item -NewName { $_.basename + "_" + (Get-Content $_).length + "_" + $_.extension}
to
Dir | Rename-Item -NewName { (Get-Content $_).length + "_" + $_.basename + $_.extension}
but it give error
Rename-Item : The input to the script block for parameter 'NewName' failed. Cannot convert value "a" to type "System.Int32". Error: "Input string was not in a correct format."
Thanks