Skip to content

Instantly share code, notes, and snippets.

@zilongshanren
Last active September 5, 2019 13:38
Show Gist options
  • Save zilongshanren/57d08f0b8872e9cab5727db322118145 to your computer and use it in GitHub Desktop.
Save zilongshanren/57d08f0b8872e9cab5727db322118145 to your computer and use it in GitHub Desktop.
批量修改源代码文件的line endings
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($TRUE)
$source = "G:\\2017.4.8f1\\2017.4.8f1\\2017.4.8f1\\"
$destination = "G:\\2017.4.8f1\\2017.4.8f1\\2017.4.8f1\\"
foreach ($i in Get-ChildItem -Recurse -Force) {
if ($i.PSIsContainer) {
continue
}
$path = $i.DirectoryName -replace $source, $destination
$name = $i.Fullname -replace $source, $destination
if(($i.Fullname -notlike "*.cpp") -and ($i.Fullname -notlike "*.h") ) {
continue;
}
if ( !(Test-Path $path) ) {
New-Item -Path $path -ItemType directory
}
$content = [IO.File]::ReadAllText($i.Fullname) -replace "`n","`r`n"
if ( $content -ne $null ) {
[System.IO.File]::WriteAllLines($name, $content, $Utf8NoBomEncoding)
} else {
Write-Host "No content from: $i"
}
}
@zilongshanren
Copy link
Author

转换后的脚本是 utf8-with-bom

@zilongshanren
Copy link
Author

解决 warning C4819: The file contains a character that cannot be represented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment