title: How to over write and write in to a textfile by using Vbscript
body: <p>i created a text file "list.txt" in commonapplicationdatafolder by using the following VBscript.i am displaying some
  values from a variable(strlist) by writing in to textfile.</p>
  
  <pre><code>Const Value = &amp;H23&amp;
  Const PATH = "\Cape\ibs"
  
  Dim fso                 ' File System Object
  Dim spFile             ' Text File object to write
  Dim objApplication      ' Application object
  Dim objFolder           ' Folder object
  Dim objFolderItem       ' FolderItem object
  
  Set objApplication  = CreateObject("Shell.Application")
  Set objFolder = objApplication.Namespace(Value)
  Set objFolderItem = objFolder.Self
  sname = objFolderItem.Path &amp; PATH &amp; "\list.txt"
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set spFile = fso.CreateTextFile(sname, True)
  spoFile.WriteLine(strlist)
  spoFile.Close
  </code></pre>
  
  <p>Here are my doubts</p>
  
  <p>1> Here before creating that file i need to delete the old existing "list.txt" Because during installation 
  i always want to create the list file.  So i want to include code that removes any existing file(any old list.txt),
  before creating the latest one.Here i did the following code</p>
  
  <pre><code>If fso.FileExists(sname) Then
      fso.DeleteFile sname, True
  Else
      Set spFile = fso.CreateTextFile(sname, True)
      spoFile.WriteLine(strlist)
      Set objFolderItem = Nothing
      Set objFolder = Nothing
      Set objApplication = Nothing
      Set fso = Nothing
      spoFile.Close
   End If
  </code></pre>
  
  <p>Whats going on is it <strong>will create folder first time,next time it will delete it</strong> ,But i always want that file there(new fresh one with value from 'strlist' )
  Can any one tell me the vbscript code to do that.Their i <strong>removed Else part</strong> also but only deletion going ,below things are not working means creation.</p>
  
  <p>2>Here i was writing in to "list.txt" by using simply 'WriteLine' method(spoFile.WriteLine(strlist)),but i read somewhere that we need to use
  'OpenTextFile'(Const ForWriting = 2) for writing,If that is the case what changes i need to do here,Is it mandatory?</p>