vbscript optimization : how to get faster file writing -


The following is the usual log function that I use in many of my vbscripts, which I am modifying accordingly. I think it's very slow to write, I get 3 questions:

  1. Any idea about optimizing it is because it writes fast?
  2. Do all the text can be faster to store the first in a string, the function output Talog play or to insert the string in the text file will be faster to execute each time Autputtolog ?
  3. If the drive is not a factor in place, then it is possible to get out of memory when writing to a text file during execution ... due to slow and slow execution of the script?

Here's my VBScript function

  function OutputToLog (strToAdd) dim strDirectory, strFile, strText, objFile, objFolder, objTextFile, objFSO strDirectory = "c: \ Log on "strFile =" \ log in - "& amp; Stampnau and ape ".bat" 'strText = "test" strText = strToAdd' filesystem object set objFSO = CreateObject ( "Scripting.FileSystemObject") to create "the present Czech strDirectory folder objFSO.FolderExists (strDirectory) then set objFolder = objFSO. GetFolder (strDirectory) or set to objFolder = objFSO.CreateFolder (strDirectory) 'WScript.Echo' just created "& amp; strDirectory finally objFSO.FileExists (strDirectory & amp; strFile) If resets objFolder = objFSO.GetFolder (strDirectory) objFile = objFSO.CreateTextFile (strDirectory & amp; strFile) or decide 'Wscript.Echo "just built" & amp; Sturdy Directory & amp; The strFile end set objFile = not set some objFolder = nothing ForAppending = 8 ForReading = 1, ForWriting = 2 'OpenTextFile method needs a Const value "Const ForAppending = 8 sets objTextFile = objFSO.OpenTextFile _ (strDirectory & amp; strFile, ForAppending, true) 'strText every time you write the VBScript objTextFile.WriteLine (strText) run objTextFile.Close end function  

thanks in advance

< / Div>

I think both of you can create their own FSO objects and output tools Open your log file out of the C function. It can not save much time, but why create objects, open and closed files with every typing?

Otherwise, if you want to keep the functions, then only one must be quick to write.


Comments