Here's the code:
Option Explicit
DIM fso: SET fso = CreateObject("Scripting.FileSystemObject")
'Declare the variables to be used from the property file
DIM Folder
DIM obNetwork
DIM strComputer, WshShell, strComputerName
strComputer = "."
SET obNetwork = Wscript.CreateObject("Wscript.Network")
strComputerName = obNetwork.ComputerName
SET obNetwork = nothing
SetConfigFromFile("C:\Users\Lenovo\Desktop\RenameFile\ConfigPad.txt")
msgbox "Folder = " & Folder
SET WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run Folder
'---------------------------------Get Variables from ConfigPad.txt------------------------
Sub SetConfigFromFile(fileName)
DIM strConfigLine
DIM fConFile
DIM EqualSignPosition
DIM strLen
DIM VariableName
DIM VariableValue
SET fConFile = fs
penTextFile(fileName)
WHILE NOT fConFile.AtEndOfStream
strConfigLine = fConFile.ReadLine
strConfigLine = TRIM(strConfigLine)
'msgbox(strConfigLine)
IF (INSTR(1,strConfigLine,"#",1) <> 1 AND LEN(strConfigLine) <> 0) THEN
EqualSignPosition = INSTR(1,strConfigLine,"=",1)
strLen = LEN(strConfigLine)
VariableName = LCASE(TRIM(MID(strConfigLine, 1, EqualSignPosition-1)))
VariableValue = TRIM(Mid(strConfigLine, EqualSignPosition + 1, strLen - EqualSignPosition))
SELECT CASE VariableName
'ADD EACH OCCURRENCE OF THE CONFIGURATION FILE VARIABLES(KEYS)
CASE LCASE("Folder")
IF VariableValue <> "" THEN Folder = VariableValue
END SELECT
END IF
WEND
fConFile.Close
End Sub
'---------------------------------Rename the documents-----------------------
Dim FLD
Dim fil
Dim strOldName
Dim strNewName
Dim strFileParts
'Set the folder you want to search.
Set FLD = FSO.GetFolder("C:\Users\Lenovo\Desktop\RenameFile\RenameFile.vbs")
'Loop through each file in the folder
For Each fil in FLD.Files
'Get complete file name with path
strOldName = fil.Path
'Check the file has an underscore in the name
If InStr(strOldName, "_") > 0 Then
'Split the file on the underscore so we can get everything before it
strFileParts = Split(strOldName, "_")
'Build the new file name with everything before the
'first under score plus the extension
strNewName = strFileParts(0) & ".txt"
'Use the MoveFile method to rename the file
FSO.MoveFile strOldName, strNewName
End If
Next
'Cleanup the objects
Set FLD = Nothing
Set FSO = Nothing