Advertisement

01.13.2006 at 05:32PM PST, ID: 21696282
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Delete line from text file

Asked by traigo in VB Controls

Tags: , , , ,

I am trying to write a VBS that will remove a line from a text file if it contains a certain string value.  I've got most of the way through, except for the part about deleting the line.  That's where I'm stuck.  The VBS will read all text files in the current directory, and remove lines from the text files based on a string comparison.

I've looked up some solutions to deleting a line from a text file, or replacing strings.  They all: opend the file, read the lines with a comparison, concantenated a string, closed the file, opened the file for writing and wrote the concantenated string.  I understand that this is very slow and I don't want to do this.  Currently, just the below code takes about 30 seconds to run.  I have lots of text files and the smaller ones have around 50,000 lines (though mostly made up of the line I'm trying to remove).

How do I delete a line?  That's the only part I'm missing.

Option Explicit

dim filepath, VBSName, objFSO, objTextFile
dim fs, folder, file, item, line
VBSname = wscript.scriptfullname

Filepath = left(VBSname, Len(VBSname) -(len(VBSname) - InstrRev(VBSname, "\")))

     set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(FilePath)

     for each item in folder.Files
      If Right(item.name, 3) = "txt" Then

      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objTextFile = objFSO.OpenTextFile (item, 1)

      Do Until objTextFile.AtEndOfStream
          Line = objTextFile.ReadLine
            If InStr(1,Line, " Host Domain: ",1)  Then

            Else

            End If
      Loop
      
      set objFSO = nothing
      set objTextFile = nothing
      End If
     next
msgbox "Done!"Start Free Trial
 
Loading Advertisement...
 
[+][-]01.13.2006 at 05:53PM PST, ID: 15697997

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 06:04PM PST, ID: 15698038

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 06:05PM PST, ID: 15698044

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 06:09PM PST, ID: 15698056

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 06:10PM PST, ID: 15698059

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 06:32PM PST, ID: 15698171

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 07:14PM PST, ID: 15698308

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: VB Controls
Tags: line, delete, file, text, from
Sign Up Now!
Solution Provided By: Idle_Mind
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.13.2006 at 07:18PM PST, ID: 15698317

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 07:20PM PST, ID: 15698324

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 07:21PM PST, ID: 15698328

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2006 at 11:40PM PST, ID: 15699076

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.14.2006 at 12:11AM PST, ID: 15699145

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.14.2006 at 12:19AM PST, ID: 15699158

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.14.2006 at 07:22AM PST, ID: 15700275

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.14.2006 at 11:16AM PST, ID: 15701395

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32