Php replacement works only for html targets in vbs

Asked 1 years ago, Updated 1 years ago, 87 views

I would like to create a program where vbs can change the contents of multiple php files to their own names at once.

I created a code similar to the one below, but it doesn't work except for html.
What should I do?

Option Explicit' variable declaration is not omitted.

Const TARGET_FOLDER="C:\Users\drive\aaa" フォルダ Specify folder
Const REPLACE_FROM = "so" 置 Pre-replacement string
Dim REPLACE_TO' Replacement String

Const ForReading=1' Load
Const ForWriting=2' Write (Overwrite Mode)
Const ForAppending = 8' Write (Additional Mode)

DimstrFilePath,infile,outfile,strData,strExt' variable declared
DimobjFSO, objFolder, objFile, objSubFolder, objTXT' variable declared
SetobjFSO=WScript.CreateObject("Scripting.FileSystemObject")' object that can manipulate drive folder files, etc.
SetobjFolder=objFSO.GetFolder (TARGET_FOLDER)

For EachobjFile InobjFolder.Files
    strFilePath=objFSO.BuildPath(TARGET_FOLDER, objFile.Name)
    strExt=objFSO.GetExtensionName(objFile.Name)
    If LCase(strExt) = "html" Then
        Set infile=objFSO.OpenTextFile(strFilePath, ForReading)
        strData=infile.ReadAll
        file.Close
        Set profile=Nothing
        Set outfile=objFSO.OpenTextFile(strFilePath, ForWriting)' (overwrite)
        REPLACE_TO=objFile.Name' *Your own filename
        outfile.WriteReplace(strData, REPLACE_FROM, REPLACE_TO)
        outfile.Close
        Set outfile=Nothing
    End If
Next

SetobjFolder=Nothing
SetobjFSO=Nothing

MsgBox "End", vbInformation

vbs

2022-09-29 22:35

1 Answers

The For statement checks for extensions in the If statement, and now it seems that you are "only for html" processing here, so if you want to target PHP, try rewriting it as follows:

before change:

strExt=objFSO.GetExtensionName(objFile.Name)
    If LCase(strExt) = "html" Then

after modification:

strExt=objFSO.GetExtensionName(objFile.Name)
    If LCase(strExt) = "php" Then


2022-09-29 22:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.