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
  • 相关阅读:
    pythone 请求响应字典
    python strip()
    python,datetime
    How Flask Routing Works
    python __file__ 与argv[0]
    Python的zip函数
    Python中的__new__()方法与实例化
    python,dict的setdefault方法
    python yield
    python with用法
  • 原文地址:https://www.cnblogs.com/micro-chen/p/14029169.html
Copyright © 2011-2022 走看看