Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 873463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:56:24+00:00 2026-05-15T10:56:24+00:00

i created a text file list.txt in commonapplicationdatafolder by using the following VBscript.i am

  • 0

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.

Const Value = &H23&
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 & PATH & "\list.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set spFile = fso.CreateTextFile(sname, True)
spoFile.WriteLine(strlist)
spoFile.Close

Here are my doubts

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

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

Whats going on is it will create folder first time,next time it will delete it ,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 removed Else part also but only deletion going ,below things are not working means creation.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:56:24+00:00Added an answer on May 15, 2026 at 10:56 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the +0 prefix is a constant, then you can… May 15, 2026 at 3:13 pm
  • Editorial Team
    Editorial Team added an answer I fixed it on my own: $nodes = $xml->getElementsByTagName('tagname'); $oldTitleNode… May 15, 2026 at 3:13 pm
  • Editorial Team
    Editorial Team added an answer Assuming the queries are of the same type, you could… May 15, 2026 at 3:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.