2024年6月12日发(作者:)

批量更改文本文件内容的方法

作者:新空教程整理 日期:2010年01月29日

批量更改文本文件内容的方法:因为各种原因,有时需要批量更改文

件文件中的内容,比如将“电脑”改成“计算机”,下面给出一个简单的

方法。

一、批处理方法:@echo offfor /f "delims=" %%i in ('dir /s/b *.txt') do

批量更改文本文件内容的方法:

因为各种原因,有时需要批量更改文件文件中的内容,比如将“电脑”

改成“计算机”,

下面给出一个简单的方法。

一、批处理方法:

@echo off

for /f "delims=" %%i in ('dir /s/b *.txt') do (

for /f "delims=" %%a in ('type "%%~fi"') do (

set "foo=%%a"

call,set foo=%%foo:电脑=计算机%%

call,echo/%%foo%%>>"%%~fi._"

)

move "%%~fi._" "%%~fi"

)

exit

将上面内容拷入文本文件,然后更改成“bat”文件,双击执行即可。

二、vb脚本的方法:

Set WshShell = CreateObject("")

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

1000

sFile = ""

Set objFSO = CreateObject("stemObject")

Set oFile = xtFile(sFile,1)

Do While Not fStream

strLine = ne

If Len(strLine) > 0 Then

Set File = xtFile(strLine, 1)

aryLines = l

aryLines = Replace(aryLines, "电脑", "计算机")

Set File = xtFile(strLine, 2)

aryLines

End If

Loop