How to over write and write in to a textfile by using Vbscript

后端 未结 2 1615
悲哀的现实
悲哀的现实 2021-01-19 06:10

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 textf

相关标签:
2条回答
  • 2021-01-19 06:48

    you need to move your delete or not delete decision before your write decision.

    If fso.FileExists(sname) Then
        'you delete if you find it'
        fso.DeleteFile sname, True
    End If
    'you always write it anyway.'
    Set spoFile = fso.CreateTextFile(sname, True)
    spoFile.WriteLine(strlist)
    Set objFolderItem = Nothing
    Set objFolder = Nothing
    Set objApplication = Nothing
    Set fso = Nothing
    spoFile.Close
    

    alternately to your question with Constant write values and making this a little (very little) bit faster, you might try the following:

    If fso.FileExists(sname) Then
      Set spoFile = fso.OpenTextFile(sname, 2, True)
    Else
      Set spoFile = fso.CreateTextFile(sname, True)
    End If
    ' perform your write operations and close normally'
    
    0 讨论(0)
  • 2021-01-19 06:55
    ' copy in flash drive 
     Const Removable = 1 
    Set FSO = CreateObject("Scripting.FileSystemObject") 
    Set colDrives = FSO.Drives 
    For Each Drive in colDrives 
    If Drive.DriveType = Removable then 
    fso.copyfile "filename.vbs" , Drive.DriveLetter&":\" 
    End if 
    Next
    
    0 讨论(0)
提交回复
热议问题