回复 18# licunwei - $ht = [Ordered]@{
- CPCIssueOrg = "车 :"
- EnTime = "时间 :"
- CPUVlp = "IC卡车牌:"
- EnVLP = "入口车牌:"
- OBUVlp = "OBU 车牌:"
- VLP = "出口车牌:"
- }
-
- $str = $ht.values -join "`n"
-
- function get-info() {
- param(
- [string]$filexml ,
- [string]$filetxt
- )
-
- [xml]$xml = Get-Content -Path $filexml -Encoding "UTF8"
- $xml.datas.data.attribute | ForEach-Object {
- if ( $_.name -eq "msg" ) { $string = $_.value }
- }
- $string = $string.Substring(1,$string.length-2)
- $string = $string -replace '(?<="),',"`n"
- $string = $string -replace '"(\w+)":"(.*)"',"`$1`t`$2"
- $as = $string -split "`n"
-
- $as | ForEach-Object {
- $a = $_ -split "`t"
- if ( $ht[$a[0]] ) {
- $str = $str -replace ( "(?m)^" + $ht[$a[0]] + ".*$" ), ( "{0} {1}" -f $ht[$a[0]] , $a[1] )
- }
- }
- $str | Out-File $filetxt
- }
-
-
- $Path = "C:\Users\admin\Desktop"
-
- Get-ChildItem -Path $Path -Filter "*.xml" | ForEach-Object {
- get-info $_.FullName ( $_.DirectoryName + "\" + $_.BaseName + ".txt")
- }
复制代码
|