Text File ammendments

Reply

Join Date: Feb 2005
Posts: 43
Reputation: Phreak is an unknown quantity at this point 
Solved Threads: 0
Phreak Phreak is offline Offline
Light Poster

Text File ammendments

 
0
  #1
Apr 26th, 2007
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' /* Edit Boot.ini's Timeout Line */
  2. call edit_bootini("c:\boot.ini")
  3.  
  4. sub edit_bootini(bootpath)
  5. dim objFileSystem
  6. ' /* Get The File System Object */
  7. set objFileSystem = createobject("Scripting.FileSystemObject")
  8.  
  9. ' /* Get The file Object (For Properties) */
  10. Set file = objFileSystem.GetFile(bootpath)
  11.  
  12. ' /* Set The File's Attributes To Normal (not system, hidden, or read only) */
  13. file.Attributes = 0
  14.  
  15. ' /* open bootpath (path to boot.ini, passed to sub from calling procedure) for reading */
  16. Set objInputFile = objFileSystem.OpenTextFile(bootpath, 1)
  17.  
  18. ' /* Read In the Entire file, and rip it apart by the newline character, storing it in an array */
  19. inputData = Split(objInputFile.ReadAll, vbNewline)
  20.  
  21. ' /* Set Our Counter Variable to 0 */
  22. cnt = 0
  23.  
  24. ' /* For Each Element In our Array (for each line of the file) */
  25. For each strData In inputData
  26.  
  27. ' /* If the first 7 characters of this line of the file is "timeout" then */
  28. if left(lcase(strData), 7) = "timeout" then
  29. ' /* change This Array's Value (This Line of the file) */
  30. inputData(cnt) = "timeout=10"
  31. end if
  32.  
  33. ' /* Add One to Our Counter Varaible */
  34. cnt = cnt + 1
  35. Next
  36.  
  37. ' /* Close The File, No changes have been to the file, only to the array (variable) that holds the lines of the file */
  38. objInputFile.Close
  39.  
  40. ' /* Create An Object To overwrite the file indicated by bootpath */
  41. Set objOutputFile = objFileSystem.CreateTextFile(bootpath, TRUE)
  42.  
  43. ' /* For each element in our array (each line of the file, Modified from original) */
  44. for each strData in inputData
  45. ' /* Write That Line to The File */
  46. objOutputFile.WriteLine strData
  47. next
  48.  
  49. ' /* Close the File (now saved with new changes) */
  50. objOutputfile.Close
  51.  
  52. ' /* Set The file To system and hidden attributes */
  53. file.Attributes = 6
  54.  
  55. ' /* Clear The File System Object */
  56. Set objFileSystem = Nothing
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 20
Reputation: shasur is an unknown quantity at this point 
Solved Threads: 1
shasur shasur is offline Offline
Newbie Poster

Re: Text File ammendments

 
0
  #2
Apr 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 43
Reputation: Phreak is an unknown quantity at this point 
Solved Threads: 0
Phreak Phreak is offline Offline
Light Poster

Re: Text File ammendments

 
0
  #3
Apr 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 20
Reputation: shasur is an unknown quantity at this point 
Solved Threads: 1
shasur shasur is offline Offline
Newbie Poster

Re: Text File ammendments

 
0
  #4
Apr 27th, 2007
Posted for the wrong thread. Please ignore
Last edited by shasur; Apr 27th, 2007 at 6:47 am. Reason: Posted for the wrong thread
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC