zoukankan      html  css  js  c++  java
  • PowerShell 搜索文件编码格式

     1 $dirFind='D:BeisenDevSrcWeb.CloudSetting'
     2 
     3 
     4 function Get-Encoding
     5 {
     6   param
     7   (
     8     [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
     9     [Alias('FullName')]
    10     [string]
    11     $Path
    12   )
    13 
    14   process 
    15   {
    16     $bom = New-Object -TypeName System.Byte[](4)
    17         
    18     $file = New-Object System.IO.FileStream($Path, 'Open', 'Read')
    19     
    20     $null = $file.Read($bom,0,4)
    21     $file.Close()
    22     $file.Dispose()
    23     
    24     $enc = [Text.Encoding]::ASCII
    25     if ($bom[0] -eq 0x2b -and $bom[1] -eq 0x2f -and $bom[2] -eq 0x76) 
    26       { $enc =  [Text.Encoding]::UTF7 }
    27     if ($bom[0] -eq 0xff -and $bom[1] -eq 0xfe) 
    28       { $enc =  [Text.Encoding]::Unicode }
    29     if ($bom[0] -eq 0xfe -and $bom[1] -eq 0xff) 
    30       { $enc =  [Text.Encoding]::BigEndianUnicode }
    31     if ($bom[0] -eq 0x00 -and $bom[1] -eq 0x00 -and $bom[2] -eq 0xfe -and $bom[3] -eq 0xff) 
    32       { $enc =  [Text.Encoding]::UTF32}
    33     if ($bom[0] -eq 0xef -and $bom[1] -eq 0xbb -and $bom[2] -eq 0xbf) 
    34       { $enc =  [Text.Encoding]::UTF8}
    35         
    36     [PSCustomObject]@{
    37       Encoding = $enc
    38       Path = $Path
    39     }
    40   }
    41 }
    42 
    43 
    44 Get-ChildItem  $dirFind -Filter *.aspx -Recurse | Get-Encoding
  • 相关阅读:
    PHP PDO
    常用JavaScript字符串方法简述
    命名
    jquery远程班备忘
    html历史
    CSS3的翻转效果
    正则
    排序算法
    firebug的调试,console
    跨域
  • 原文地址:https://www.cnblogs.com/micro-chen/p/14029169.html
Copyright © 2011-2022 走看看