Eu posso reproduzir seu problema usando o próximo script Powershell simples
$RatedName = "šöü" # set sample string
$FormDName = $RatedName.Normalize("FormD") # its Canonical Decomposition
$FormCName = $FormDName.Normalize("FormC") # followed by Canonical Composition
# list each string character by character
($RatedName,$FormDName,$FormCName) | ForEach-Object {
$charArr = [char[]]$_
"$_" # display string in new line for better readability
# display each character together with its Unicode codepoint
For( $i=0; $i -lt $charArr.Count; $i++ ) {
$charInt = [int]$charArr[$i]
# next "Try-Catch-Finally" code snippet adopted from my "Alt KeyCode Finder"
# http://superuser.com/a/1047961/376602
Try {
# Get-CharInfo module downloadable from http://poshcode.org/5234
# to add it into the current session: use Import-Module cmdlet
$charInt | Get-CharInfo |% {
$ChUCode = $_.CodePoint
$ChCtgry = $_.Category
$ChDescr = $_.Description
}
}
Catch {
$ChUCode = "U+{0:x4}" -f $charInt
if ( $charInt -le 0x1F -or ($charInt -ge 0x7F -and $charInt -le 0x9F))
{ $ChCtgry = "Control" } else { $ChCtgry = "" }
$ChDescr = ""
}
Finally { $ChOut = $charArr[$i] }
"{0} {1,-2} {2} {3,5} {4}" -f $i, $charArr[$i], $ChUCode, $charInt, $ChDescr
}
}
# create sample files
$RatedName | Out-File "D:\test97217Rated$RatedName.txt" -Encoding utf8
$FormDName | Out-File "D:\test97217FormD$FormDName.txt" -Encoding utf8
$FormCName | Out-File "D:\test97217FormC$FormCName.txt" -Encoding utf8
"" # very artless draft of possible solution
Get-ChildItem "D:\test97217*" | ForEach-Object {
$y = $_.Name.Normalize("FormC")
if ( $y.Length -ne $_.Name.Length ) {
Rename-Item -NewName $y -LiteralPath $_ -WhatIf
} else {
" : file name is already normalized $_"
}
}
O script acima é atualizado da seguinte forma: 1º mostra mais informações sobre caracteres Unicode compostos / decompostos, isto é, seus nomes Unicode (consulte Módulo Get-CharInfo ); 2º rascunho muito de possível solução.
Saída do prompt cmd
:
==> powershell -c D:\PShell\SU97217.ps1
šöü
0 š U+0161 353 Latin Small Letter S With Caron
1 ö U+00F6 246 Latin Small Letter O With Diaeresis
2 ü U+00FC 252 Latin Small Letter U With Diaeresis
šöü
0 s U+0073 115 Latin Small Letter S
1 ̌ U+030C 780 Combining Caron
2 o U+006F 111 Latin Small Letter O
3 ̈ U+0308 776 Combining Diaeresis
4 u U+0075 117 Latin Small Letter U
5 ̈ U+0308 776 Combining Diaeresis
šöü
0 š U+0161 353 Latin Small Letter S With Caron
1 ö U+00F6 246 Latin Small Letter O With Diaeresis
2 ü U+00FC 252 Latin Small Letter U With Diaeresis
: file name is already normalized D:\test97217FormCšöü.txt
What if: Performing the operation "Rename File" on target "Item: D:\test97217
FormDšöü.txt Destination: D:\test97217FormDšöü.txt".
: file name is already normalized D:\test97217Ratedšöü.txt
==> dir /b D:\test97217*
1097217FormCšöü.txt
1097217FormDšöü.txt
1097217Ratedšöü.txt
De fato, acima de dir
output parece como a janela 1097217FormDsˇo¨u¨.txt
in cmd
e meu navegador com reconhecimento de unicode compõe strings conforme listado acima, mas analisador unicode mostra os personagens verdadeiramente, assim como a imagem mais recente:
Noentanto,opróximoexemplomostraoproblemaemtodaasualargura:umloopfor
mudacombinandoacentosparanormaluns:
==>for/F"delims=" %G in ('dir /b /S D:\test97217*') do @echo %~nxG & dir /B %~fG
1097217FormCšöü.txt
1097217FormCšöü.txt
1097217FormDsˇo¨u¨.txt
File Not Found
1097217Ratedšöü.txt
1097217Ratedšöü.txt
== >
Aqui está muito esboço sem arte de possível solução (veja o resultado acima):
"" # very artless draft of possible solution
Get-ChildItem "D:\test97217*" | ForEach-Object {
$y = $_.Name.Normalize("FormC")
if ( $y.Length -ne $_.Name.Length ) {
Rename-Item -NewName $y -LiteralPath $_ -WhatIf
} else {
" : file name is already normalized $_"
}
}
( ToDo : invoque Rename-Item
apenas se necessário):
Get-ChildItem "D:\test97217*" | ForEach-Object {
$y = $_.Name.Normalize("FormC")
if ($true) { ### ToDo
Rename-Item -NewName $y -LiteralPath $_ -WhatIf
}
}
e sua saída (novamente, aqui estão strings compostas e a imagem abaixo mostra cmd
window look unbiased) :
What if: Performing the operation "Rename File" on target "Item: D:\test97217
FormCšöü.txt Destination: D:\test97217FormCšöü.txt".
What if: Performing the operation "Rename File" on target "Item: D:\test97217
FormDšöü.txt Destination: D:\test97217FormDšöü.txt".
What if: Performing the operation "Rename File" on target "Item: D:\test97217
Ratedšöü.txt Destination: D:\test97217Ratedšöü.txt".
Atualizadocmd
output