Skip to content

Instantly share code, notes, and snippets.

@gsusI
Last active February 7, 2023 16:40
Show Gist options
  • Save gsusI/b4a01901e33b8b09921fdbd976a613ec to your computer and use it in GitHub Desktop.
Save gsusI/b4a01901e33b8b09921fdbd976a613ec to your computer and use it in GitHub Desktop.
EOL from CRLF to LF recursively: this script will convert all files in the current directory and all subdirectories to unix line endings
# Set the parameters
$path = Get-Location
$numbOfThreads = 50
$exclude_patterns = "^.*(\.git|\.idea|node_modules|\.next|\.(jpeg|jpg|png|gif|mp4|mkv|mp3|wav)$).*$"
# Find filles to convert
$files = Get-ChildItem -Path $path -Recurse -Include * -File -Force | Where-Object {$_.FullName -notmatch $exclude_patterns}
Write-Host "Found $($files.Count) files"
$files | ForEach-Object -Parallel {
if ((Get-Content $_.FullName -Raw) -match "\r") {
Write-Host "Converting $($_.FullName)"
dos2unix $_.FullName
}
} -ThrottleLimit $numbOfThreads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment