bat批量处理 把当前目录下所有TXT文件内容 )改成))?

bat批量处理
把当前目录下所有TXT文件,在每个TXT文本内容里面 ,
把 ) 改成 )); 把GT改成GS; 直接修改不用生成新文本、
求高手帮忙 万分感激

以下代码复制到记事本,另存为VBS脚本,放在你要执行的文件夹里面。设置如下,注意红色部分。

Set WshShell = CreateObject("Wscript.Shell")

WshShell.Run "cmd /c dir /s /b *.txt > Temp.txt",vbHide

Wscript.Sleep 1000 


sFile = "Temp.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oFile = objFSO.OpenTextFile(sFile,1)

Do While Not oFile.AtEndOfStream

strLine = oFile.ReadLine

If Len(strLine) > 0 Then

Set File = objFSO.OpenTextFile(strLine, 1)

aryLines = File.ReadAll

File.Close

aryLines = Replace(aryLines, ")", "))")

aryLines = Replace(aryLines, "GT", "GS")

Set File = objFSO.OpenTextFile(strLine, 2)

File.Write aryLines

File.Close

End If

Loop

oFile.Close


objFSO.DeleteFile sFile

Set objFSO = Nothing

msgbox "Done!",64,"TXT"

温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-03-21
不清楚你的实际文件/情况,仅以问题中的样例/说明为据
复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起运行<# :
cls
@echo off
rem 将多个txt文本文件里的指定内容/固定内容替换成其他内容
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
   
$folder='.'; 
$enc=[Text.Encoding]::Default;
$files=@(dir -liter $folder -recurse|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
    write-host $files[$i].Name;
    $oldtext=[IO.File]::ReadAllText($files[$i].FullName, $enc);
    $newtext=$oldtext.replace(')', '))').replace('GT', 'GS');
    [IO.File]::WriteAllText($files[$i].FullName, $newtext, $enc);
};

相似回答