- <# :
- cls&echo off&cd /d "%~dp0"&rem bat存为ANSI/GB2312编码
- set "current=%cd%"
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $findword=@'
- 指定的字符串1
- 指定的字符串2
- '@;
-
- $suffix='添加字符';
-
- $arr=$findword.trim("`r`n") -split '[\r\n]+';
- $current=$env:current;
- $enc=[Text.Encoding]::GetEncoding('GB2312');
- $files=@(dir -literal $current|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i].FullName.Substring($current.length+1);
- $text=[IO.File]::ReadAllText($files[$i].FullName, $enc);
- for($j=0;$j -lt $arr.length;$j++){
- $newword=$arr[$j]+$suffix;
- $text=$text.replace($arr[$j], $newword);
- }
- [IO.File]::WriteAllText($files[$i].FullName, $text, $enc);
- }
复制代码
|