Can you help with amending this code, so it no longer looks at the boot ini, but will look at apx 200 separate texts files called "textfile1.txt" "textfile2.txt" etc etc consecutively for the line of text "Max100" and remove and replace with "max200"

This is a piece of code from a previous script that locates the boot.ini at c:\boot.ini and searches it for a dupe entry and removes it... any help would be appreciated

Thanks in advance

' /* Edit Boot.ini's Timeout Line */
call edit_bootini("c:\boot.ini")

sub edit_bootini(bootpath)
	dim objFileSystem
	' /* Get The File System Object */
	set objFileSystem = createobject("Scripting.FileSystemObject")

	' /* Get The file Object (For Properties) */
	Set file = objFileSystem.GetFile(bootpath)

	' /* Set The File's Attributes To Normal (not system, hidden, or read only) */
	file.Attributes = 0

	' /* open bootpath (path to boot.ini, passed to sub from calling procedure) for reading */
	Set objInputFile = objFileSystem.OpenTextFile(bootpath, 1)

	' /* Read In the Entire file, and rip it apart by the newline character, storing it in an array */
	inputData = Split(objInputFile.ReadAll, vbNewline)

	' /* Set Our Counter Variable to 0 */
	cnt = 0
	' /* For Each Element In our Array (for each line of the file) */
	For each strData In inputData
		' /* If the first 7 characters of this line of the file is "timeout" then */
		if left(lcase(strData), 7) = "timeout" then
			' /* change This Array's Value (This Line of the file) */
			inputData(cnt) = "timeout=10"
		end if	

		' /* Add One to Our Counter Varaible */
		cnt = cnt + 1

	' /* Close The File, No changes have been to the file, only to the array (variable) that holds the lines of the file */

	' /* Create An Object To overwrite the file indicated by bootpath */
	Set objOutputFile = objFileSystem.CreateTextFile(bootpath, TRUE)

	' /* For each element in our array (each line of the file, Modified from original) */
	for each strData in inputData
		' /* Write That Line to The File */
		objOutputFile.WriteLine strData

	' /* Close the File (now saved with new changes) */

	' /* Set The file To system and hidden attributes */
	file.Attributes = 6

	' /* Clear The File System Object */
	Set objFileSystem = Nothing
9 Years
Discussion Span
Last Post by shasur

This will do the iteration

Sub Modify_Trial()
Dim i
'/* Edit Boot.ini's Timeout Line */
'Call edit_bootini("c:\boot.ini")
For i = 1 To 100
Call edit_bootini("c:\textfile" & i & ".ini")
Next i

End Sub

Then in the new procedure
read the file

use the replace () function to change the required string and write the file



Thanks for the advice, although I am a little confused?

I want to create a vbs script that will sit in the same directory as the "textfile1.txt" etc and once run it will open each text file consecutively and search the file for a reference to "max100" and then change that reference to "max200" and save the file and move on to the next file "textfile3.txt" etc etc and so on...

the bootini is no longer required but this code (with help from comatose) does contain a lot of the required features I need as it does very similar tasks. Basically what is required is a script to open up consecutive ".txt" files and change all references of "max100" to "max200"

any help is greatly appreciated


This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.