Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. function Convert-Eol() {
  2. Param(
  3. [Parameter(Mandatory=$true)]
  4. [ValidateNotNullOrEmpty()]
  5. [string[]] $Files,
  6.  
  7. [Parameter(Mandatory=$false)]
  8. [ValidateNotNullOrEmpty()]
  9. [Text.Encoding] $Encoding = [Text.Encoding]::Default,
  10.  
  11. [Parameter(Mandatory=$true)]
  12. [ValidateNotNullOrEmpty()]
  13. [ValidateSet("Cr", "Crlf", "Lf")]
  14. [string] $Eol
  15. )
  16.  
  17. $eols = @{
  18. "Cr" = "`r";
  19. "Crlf" = "`r`n";
  20. "Lf" = "`n";
  21. }
  22.  
  23. foreach ($file in $Files) {
  24. $file = Resolve-Path $file
  25.  
  26. $text = [IO.File]::ReadAllText($file)
  27. if ($Eol -ne "Lf") {
  28. $text = $text -replace $eols["Lf"], $eols[$Eol]
  29. }
  30.  
  31. [IO.File]::WriteAllText($file, $text)
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement