file - 使用 VBS 替换多个文本文件中的文本
问题描述
我正在尝试编写一个 VBS 脚本,该脚本将循环遍历多个文本文件并用其他词替换几个关键字,例如用 GJA 替换 1ECODE。我有工作代码可以为单个文件执行此操作,该文件在代码中进行了详细说明,但无法使其循环浏览多个文本文件。
我当前的代码(来自另一个线程)低于返回错误“对象不支持此属性或方法'f.FullName'
要编辑的文件都称为“testfile_1.txt”、“testfile_2.txt”等
任何人都可以提供任何帮助将不胜感激
Set fso = CreateObject("Scripting.FileSystemObject")
Set prefixes = CreateObject("Scripting.Dictionary")
prefixes.CompareMode = vbTextCompare 'make dictionary lookups case-insensitive
prefixes.Add "testfile", True
For Each f In fso.GetFolder("C:\Users\msi\Documents\script_test\Test_folder").Files
If InStr(f.Name, "_") > 0 Then
If prefixes.Exists(Split(f.Name, "_")(0)) Then
strText = fso.OpenTextFile(f.FullName).ReadAll
strText = Replace(strText, "1ECODE", "ELH")
strText = Replace(strText, "1GCODE", "GLH")
strText = Replace(strText, "2ECODE", "EQT")
strText = Replace(strText, "2GCODE", "GQT")
strText = Replace(strText, "3ECODE", "EQT")
strText = Replace(strText, "3GCODE", "GQT")
fso.OpenTextFile(f.FullName, 2).Write strText
End If
End IF
Next
解决方案
File
对象没有FullName
属性,Path
而是使用。
推荐阅读
- javascript - 如何在新的构建反应项目后删除缓存
- redirect - Http tp Https URL re-write rule for app.hostname.com in IIS
- python - 如何在子进程中使用 tr 命令
- angular - Default routing to path with dynamic id
- c++ - 这在运行时是否允许?你如何提取类似堆栈的东西的前 N 个元素?
- php - PHP array get values
- bash - Shell script finally block
- typescript - 打字稿:确保函数可以返回联合类型中的每个值
- vba - Application.wait 没有在它被写入的地方执行
- python - 为什么 Sqlite3 表不会更新