需要批量替换多级目录下所有txt内的指定字符,不清楚如果批量修改指定目录下多个多级文件夹下的txt文件,求助,以下是找的单个修改的代码可以用,不知道如何修改for才行- <# :
- cls&echo off&cd /d "%~dp0"
- rem 将当前目录里的一个dat文件里的指定字符内容替换成其他指定字符内容
- set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
- title %#% +%$%%$%/%_% %z%
- set "current=%cd%"&set "tmpfile=%tmp%\t.t"
- dir /a-d-h/b "*.txt">"%tmpfile%"
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- echo;%#% +%$%%$%/%_% %z%
- exit
- #>
- $tmpfile=$env:tmpfile;
- $outfolder=($env:current).trimend("\")+"\result";
- if(-not (test-path -literal $outfolder)){[void][IO.Directory]::CreateDirectory($outfolder);}
- $enc=[Text.Encoding]::GetEncoding('GB2312');
- $files=[IO.File]::ReadAllLines($tmpfile, $enc);
- if($files.Count -ge 1){$files[0];
- $text=[IO.File]::ReadAllText($files[0], $enc);
- $text=$text.replace(',', ' ');
- $newfile=$outfolder+'\'+$files[0];
- [IO.File]::WriteAllText($newfile, $text, $enc);
- }
复制代码
|