热心网友
回答时间:2023-09-20 12:40
大量文本的话用VBS吧,效率比批处理高:
'******************************************************
Const ForWriting = 2
Const ForReading = 1
' 以下路径按实际更改
strFolder = "e:\temp"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
'******************************************************
For Each objFile in colFiles
Set strFile = FSO.OpenTextFile(objFile)
If not strFile.AtEndOfStream Then
strLines = strFile.ReadAll
End If
strFile.Close
strNum = Left(objFile.Name, Len(objFile.name) - 4)
strNewString = Replace(strLines, "000",strNum)
Set strFile = FSO.OpenTextFile(objFile, ForWriting)
strFile.Write strNewString
strFile.Close
Next
'******************************************************
Set FSO = Nothing
Wscript.Quit
收起
热心网友
回答时间:2023-09-20 12:40
将以下内容保存为批处理文件,和8000个文件放一起运行即可,请先做好备份。
@echo off&setlocal enabledelayedexpansion
for /r %%a in (*.txt)do (
cls&echo 正在处理%%~nxa,请稍候...
for /f "tokens=1,* delims=:" %%b in ('type "%%a"')do (
set .=%%b
set .=!.:000=%%~na!
echo=!.!>>#.txt
)
move #.txt "%%a"
)
echo 处理完成&pause>nul
收起