本帖最后由 terse 于 2013-11-10 15:26 编辑
这样处理了 帮看下行不
重新编辑一下规则- $n = 1.5
- $m = 2.5
- $Ph = "c:\te st"
- $Ext = "txt"
- $Reg = '(?i)(\\pos\()(\d+),(\d+)'
- function GetEncoding ($ph)
- {
- $ByteStr = Get-Content -LiteralPath $Ph -Encoding Byte -TotalCount 3
- $BOM = "{0:X}{1:X}{2:X}" -f $ByteStr
- if ($BOM -eq "EFBBBF")
- {
- "UTF8"
- }
- Else
- {
- $BOM = "{0:X}{1:X}" -f $ByteStr
- if ($BOM -eq "FFFE")
- {
- "Unicode"
- }
- Elseif ($BOM -eq "FEFF")
- {
- "BigEndianUnicode"
- }
- Else {"Ascii"}
- }
- }
-
- function GetReplace($a)
- {
- $a -match $Reg |out-null
- "$($matches[1])$([int]($n * [int] $matches[2])),$([int]($m * [int] $matches[3]))"
- }
-
- foreach ($File in Get-Childitem "$Ph\*" -include *.$Ext)
- {
- $Encoding = GetEncoding($File)
- (Get-Content -LiteralPath $File| % {
- [RegEx]::Replace($_,$Reg,{param($a)GetReplace($a)})
- })| Set-Content -Encoding $Encoding -LiteralPath $File
- }
复制代码
|