VBS 如何用新值替换任何颜色字符串 (#******)
VBS How to replace any color string (#******) with new value
尝试用新颜色值替换文件夹中的不同颜色值这是我的起始代码:
Option Explicit
Dim objFSO, strFolder, objFolder, objFile
Dim strOldValue, strNewValue, objRead, strContents, objWrite
Const ForReading = 1
Const ForWriting = 2
strFolder = "..\..\chrome\OPCEN\TABS"
strOldValue = "#******"
strNewValue = "#F5F5F5"
更新:这是使用 RegEx 的工作代码(但指向文件而不是整个文件夹)
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("..\..\chrome\OPCEN\TABS\tabs.css", ForReading)
strText = objFile.ReadAll
objFile.Close
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = False
objRegEx.Pattern = "\#[A-Z 0-9]{6}"
strNewText = objRegEx.Replace(strText, "#F5F5F5")
Set objFile = objFSO.OpenTextFile("..\..\chrome\OPCEN\TABS\tabs.css", ForWriting)
objFile.WriteLine strNewText
objFile.Close
使用 For Each loop to processing files and Regular Expressions 替换您的字符串。
试试我的方法:
Const ForReading = 1
Const ForWriting = 2
Set fso=Createobject("Scripting.FileSystemObject")
Set objRegEx = New RegExp
FolderName = "..\..\chrome\OPCEN\TABS"
Set objFolder = fso.GetFolder(FolderName)
Set objFileCol = objFolder.Files
For Each obFile In objFileCol
If Right(obFile,3)="css" Then 'Check all files extensions.
Set objFile = fso.OpenTextFile(obFile, ForReading)
strText = objFile.ReadAll
objFile.Close
objRegEx.Global = True
objRegEx.IgnoreCase = False
objRegEx.Pattern = "\#[A-Z 0-9]{6}"
strNewText = objRegEx.Replace(strText, "#F5F5F5")
Set WriteFile = fso.OpenTextFile(obFile, ForWriting)
WriteFile.WriteLine strNewText
WriteFile.Close
End if
Next
尝试用新颜色值替换文件夹中的不同颜色值这是我的起始代码:
Option Explicit
Dim objFSO, strFolder, objFolder, objFile
Dim strOldValue, strNewValue, objRead, strContents, objWrite
Const ForReading = 1
Const ForWriting = 2
strFolder = "..\..\chrome\OPCEN\TABS"
strOldValue = "#******"
strNewValue = "#F5F5F5"
更新:这是使用 RegEx 的工作代码(但指向文件而不是整个文件夹)
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("..\..\chrome\OPCEN\TABS\tabs.css", ForReading)
strText = objFile.ReadAll
objFile.Close
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = False
objRegEx.Pattern = "\#[A-Z 0-9]{6}"
strNewText = objRegEx.Replace(strText, "#F5F5F5")
Set objFile = objFSO.OpenTextFile("..\..\chrome\OPCEN\TABS\tabs.css", ForWriting)
objFile.WriteLine strNewText
objFile.Close
使用 For Each loop to processing files and Regular Expressions 替换您的字符串。
试试我的方法:
Const ForReading = 1
Const ForWriting = 2
Set fso=Createobject("Scripting.FileSystemObject")
Set objRegEx = New RegExp
FolderName = "..\..\chrome\OPCEN\TABS"
Set objFolder = fso.GetFolder(FolderName)
Set objFileCol = objFolder.Files
For Each obFile In objFileCol
If Right(obFile,3)="css" Then 'Check all files extensions.
Set objFile = fso.OpenTextFile(obFile, ForReading)
strText = objFile.ReadAll
objFile.Close
objRegEx.Global = True
objRegEx.IgnoreCase = False
objRegEx.Pattern = "\#[A-Z 0-9]{6}"
strNewText = objRegEx.Replace(strText, "#F5F5F5")
Set WriteFile = fso.OpenTextFile(obFile, ForWriting)
WriteFile.WriteLine strNewText
WriteFile.Close
End if
Next