5 Replies - 1016 Views - Last Post: 11 June 2014 - 07:05 AM Rate Topic: -----

#1 ApprenticeAlexH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Delete lines of txt untill a certain string is met

Posted 10 June 2014 - 04:48 AM

Hi everyone,
I'm currently undergoing a Software Development Apprenticeship,
I have been set a task on VBscript which I have little experience with.
I've been through the Scripting: Your First Steps guide via the Script Centre and am now familiar with the basis on how scripts run - ect..

My task is to be able to write a script which:
- Removes all blank lines of a txt file (my txt file contains about 200 lines of text)
-Deletes all lines untill a specific string is met (I need the straing that starts with REPORTS=CLUC)
-Then over write the txt file


A friend advised me to ask for help and guidance on here as he says everyone is very helpful.
A nice donation via Paypal would never be unheard of in my books if help was given.
Kindest Regards to everyone & I hope someone out there can help.
Alex.

Is This A Good Question/Topic? 0
  • +

Replies To: Delete lines of txt untill a certain string is met

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9424
  • View blog
  • Posts: 35,417
  • Joined: 12-June 08

Re: Delete lines of txt untill a certain string is met

Posted 10 June 2014 - 05:27 AM

What have you tried, researched, or attempted?
Was This Post Helpful? 0
  • +
  • -

#3 ApprenticeAlexH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Re: Delete lines of txt untill a certain string is met

Posted 10 June 2014 - 05:52 AM

I've tried to firstly start by deleting all blank lines, the hardest park is deleting all lines up untill the string I want is met, Is it even possible in VBScript? :S
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9424
  • View blog
  • Posts: 35,417
  • Joined: 12-June 08

Re: Delete lines of txt untill a certain string is met

Posted 10 June 2014 - 06:36 AM

Sure.. it is quite possible.
Was This Post Helpful? 0
  • +
  • -

#5 ApprenticeAlexH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Re: Delete lines of txt untill a certain string is met

Posted 11 June 2014 - 06:55 AM

Hi guys.

Here is my current code which deletes all text until a string is met.

want I need help with is how I can add to this code in order to remove all blank lines for every txt file within a folder?

if anyone could help would be much appreciated!!

Regards,

Alex.

_____________________________________________________________

dim fso, folder, files, contents, tempFO, index

set fso = CreateObject("Scripting.FileSystemObject")
set folder = fso.GetFolder("C:\Scripting")
set files = folder.Files

For Each file in files
set tempFO = fso.OpenTextFile(file, 1)
contents = tempFO.ReadAll()
tempFO.Close()
index = instr(contents, "REPORTS=CLUC")

If index > 0 Then
set tempFO = fso.OpenTextFile(file, 2)
tempFO.Write(Mid(contents, index))
tempFO.Close()
End if
Next

________________________________________________________________
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9424
  • View blog
  • Posts: 35,417
  • Joined: 12-June 08

Re: Delete lines of txt untill a certain string is met

Posted 11 June 2014 - 07:05 AM

Please do not create duplicate topics. Merging.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1