Hi

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
	Next

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

	' /* 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
	next 

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

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

	' /* Clear The File System Object */
	Set objFileSystem = Nothing

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

Hi,

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

TIA

Posted for the wrong thread. Please ignore

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.