I'm trying to batch rename plain text files using the first line of each file. I want to keep only alphanumeric characters in with your help I'm almost there. The only issue is that I need accented characters like é
or á
to be preserved in a form of their respective not accented characters: e and a (text is in Spanish) or be preserved in the name as they are, not removed. This is what I'm using right now:
Get-ChildItem *.txt | Rename-Item -NewName {
$firstLine = ($_ | Get-Content -TotalCount 1) -replace '[^a-z0-9 ]'
'{0}.txt' -f $firstLine
}
Thank you. If possible, please let me know if there is a way to keep the symbol "?" too.