GPT答: |
7i24.cn
|
Sub 读取文件夹中所有文本文件并替换作业()
Dim FolderName As String
FolderName = InputBox("请输入文件夹的全路径:")
Dim FileName As String
FileName = Dir(FolderName & "\*.*", vbNormal)
Do While FileName <> ""
If Right$(FileName, 3) = "txt" Then
Dim FPath As String
FPath = FolderName & "\" & FileName
Dim txtContent As String
Open FPath For Input As #1
txtContent = Input(LOF(1), #1)
Close #1
txtContent = Replace(txtContent, "作业", "作文")
Open FPath For Output As #1
Print #1, txtContent
Close #1
End If
FileName = Dir
Loop
MsgBox ("内容已替换!")
End Sub
|