Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB

  1. dim CommandLine
  2. dim SourceFileContents(50000)
  3. dim counter
  4. dim TargetFile
  5. set CommandLine=wscript.arguments
  6. if CommandLine.Count < 2 then
  7. Usage
  8. else
  9. doMain CommandLine(0), CommandLine(1), CommandLine(2)
  10. end if
  11. sub Usage
  12. wscript.stdout.write "USAGE: ReplaceText.vbs <fileName> <Serach String> <Replace Value>"
  13. end sub
  14. sub doMain ( strFileName, strSearchString, strReplaceValue )
  15. OpenSourceFile strFileName
  16. OpenTargetFile strFileName
  17. FindAndReplace strSearchString, strReplaceValue
  18. end sub
  19. sub FindAndReplace( strSearchString, strReplaceValue )
  20. Println "Searching for: " & strSearchString & " and will replace with: " & strReplaceValue
  21. println "Total lines: " & Counter
  22. for i = 1 to counter
  23. if instr( 1, SourceFileContents(i), strSearchString ) then
  24. PrintLn "Found at line: " & i
  25. TargetFile.WriteLine strReplaceValue
  26. else
  27. TargetFile.WriteLine SourceFileContents(i)
  28. end if
  29. next
  30. end sub
  31. sub OpenSourceFile ( strFileName )
  32. set FileSystemObject=CreateObject("Scripting.FileSystemObject")
  33. set SourceFile=FileSystemObject.OpenTextFile( strFileName )
  34. counter=1
  35. do while SourceFile.AtEndOfStream <> true
  36. SourceFileContents(counter)= SourceFile.ReadLine
  37. counter=counter+1
  38. loop
  39. SourceFile.close()
  40. end sub
  41. sub OpenTargetFile ( strFileName )
  42. set FileSystemObject=CreateObject("Scripting.FileSystemObject")
  43. set TargetFile=FileSystemObject.CreateTextFile( strFileName, true )
  44. end sub
  45. '*****************************************************************************************************
  46. ' Helper Routines
  47. '*****************************************************************************************************
  48. sub PrintLn( Text )
  49. wScript.StdOut.Write Text & vbLf
  50. end sub
  51. sub Print( Text )
  52. wScript.StdOut.Write Text
  53. end sub