Functions/Data/Test-Ascii.ps1
function Test-Ascii { [Cmdletbinding()] Param ( # File Item to Test [parameter()] [System.IO.FileInfo] $Item ) begin { $validList = [System.Collections.ArrayList]::new() $validList.AddRange([byte[]] (10,13) ) $validList.AddRange([byte[]] (31..127) ) } process { try { $reader = $item.Open([System.IO.FileMode]::Open) $bytes = new-object byte[] 1024 $numRead = $reader.Read($bytes, 0, $bytes.Count) for($i=0; $i -lt $numRead; ++$i) { if (!$validList.Contains($bytes[$i])) {return $false}} $true } finally {if ($reader) {$reader.Dispose()}} } } |