Last active
September 5, 2019 13:38
-
-
Save zilongshanren/57d08f0b8872e9cab5727db322118145 to your computer and use it in GitHub Desktop.
批量修改源代码文件的line endings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" | |
} | |
} |
source = destination 可以执行inplace替换
该脚本适用于windows平台
转换后的脚本是 utf8-with-bom
解决 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
这是一个powershell脚本