Topic Options
#57043 - 05/17/19 12:32 PM remove number of line from data file
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
Hi, can some one help me with a code to remove first 15 line of a data from a data file. I'm stuck for a job running late!

THANKS


Edited by Sami786 (05/17/19 12:35 PM)
_________________________
Peace

Top
#57044 - 05/17/19 01:05 PM Re: remove number of line from data file [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
I'm trying this but it's not working, can someone take a look.

In my workflow I have folder capture then I need to have this to remove the first 15 lines then follows.

iNumberOfLinesToDelete = 15

Set objFS = CreateObject("Scripting.FileSystemObject")

arrLines = Split(strContents, vbNewLine)

For i=0 To UBound(arrLines)
If i > (iNumberOfLinesToDelete - 1) Then
objTS.WriteLine arrLines(i)
End If
Next


Edited by Sami786 (05/17/19 01:10 PM)
_________________________
Peace

Top
#57045 - 05/17/19 02:03 PM Re: remove number of line from data file [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
my script works if I read a data file from a folder, how can I change this code to work on the process directly and not from a folder:

Const FOR_READING = 1
Const FOR_WRITING = 2
strFileName = "C:\Temp\test.txt"
iNumberOfLinesToDelete = 15

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close

arrLines = Split(strContents, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, FOR_WRITING)

For i=0 To UBound(arrLines)
If i > (iNumberOfLinesToDelete - 1) Then
objTS.WriteLine arrLines(i)
End If
Next


Edited by Sami786 (05/17/19 03:06 PM)
_________________________
Peace

Top
#57046 - 05/17/19 03:05 PM Re: remove number of line from data file [Re: Sami786]
jouberto Offline
OL Toddler

Registered: 04/18/18
Posts: 32
Hi Sami,

The workflow has a plugin called add/remove text, which lets you remove 15 lines from the beginning of your data file. You should find it pretty straightforward to configure.

Regards,

Top
#57047 - 05/17/19 03:25 PM Re: remove number of line from data file [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
thank you but I also need to delete some line in between when I need to. That's why I need this script to work. THANKS
_________________________
Peace

Top
#57048 - 05/17/19 03:30 PM Re: remove number of line from data file [Re: Sami786]
jouberto Offline
OL Toddler

Registered: 04/18/18
Posts: 32
Hi Sami,

Here is a script that will read your input data stream and write to your data stream. Anything that needs to be modified can be programmed where indicated (prevent writing specific lines, edit the lines, add to the existing data, etc...)
Code:
Option explicit
Dim objFSO
Dim objInputFile, objOutputFile
Dim sTempName, sTempPath, sLine

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(Watch.GetJobFilename, 1)
sTempPath = objFSO.GetFile(Watch.GetJobFilename).ParentFolder.Path
sTempName = objFSO.GetTempName
Set objOutputFile = objFSO.GetFolder(sTempPath).CreateTextFile(sTempName)

Do While not(objInputFile.AtEndOfStream)
  sLine = objInputFile.ReadLine
  ***put your logic here****
  objOutputFile.WriteLine(sLine)
Loop

objInputFile.Close
objOutputFile.Close
objFSO.DeleteFile Watch.GetJobFilename, true
objFSO.MoveFile sTempPath & "\" & sTempName, Watch.GetJobFilename

Top
#57049 - 05/17/19 04:25 PM Re: remove number of line from data file [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 324
Loc: Home
great, thank you sooooooo much smile

Happy Friday
_________________________
Peace

Top