- Dir = "==NC=="
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- For Each file in fso.GetFolder(Dir).Files
- Ext = fso.GetExtensionName(file)
- If Lcase(Ext) = "nc" or Lcase(Ext) = "txt" _
- or Lcase(Ext) = "ncd" or Lcase(Ext) = "pim" Then
- ReplaceStr fso.OpenTextFile(file,1).ReadAll
- End If
- Next
-
- Sub ReplaceStr(str)
- Dim re_str1, re_str2
- Set re = New RegExp
- re.Pattern = "==DK_T(2)?=="
- re.Global = True
- re.IgnoreCase = True
- If not re.Test(str) Then Exit Sub
- Do Until RegEx(a)
- a = InputBox("===输入编号[1~999]===",file.Name,"1")
- If IsEmpty(a) Then Exit Sub
- Loop
-
- re_str1 = Replace(str, "==DK_T==", "G43T" & a)
- re_str2 = Replace(re_str1, "==DK_T2==", "M6H" & a & "Z100")
- fso.OpenTextFile(file,2).Write re_str2
- End Sub
-
- Function RegEx(a)
- Set reg = New RegExp
- reg.Pattern = "^[1-9]\d{0,2}$"
- RegEx = reg.Test(a)
- End function
复制代码
|