Advertisement
guyrleech

Get Text File Encoding

Oct 24th, 2022
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. ## Get text encoding of files
  2. ## from js2010 on https://stackoverflow.com/questions/3825390/effective-way-to-find-any-files-encoding
  3.  
  4. foreach($filename in $args)
  5. {
  6. ##$reader = [System.IO.StreamReader]::new($filename, [System.Text.Encoding]::default,$true)
  7. ## changed to work with earlier (legacy) PowerShell versions
  8. if( $reader = New-Object -TypeName System.IO.StreamReader -ArgumentList @($filename, [System.Text.Encoding]::default,$true) )
  9. {
  10. $peek = $reader.Peek()
  11. $reader.currentencoding | Select-Object -property @{n='File';e={$filename}},bodyname,encodingname
  12. $reader.close()
  13. }
  14. }
  15.  
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement