KB-36190: Grouping text files.

Question:

How can I group several TXT files into a single one?

Solution:

To do so, you must create a script to read each file’s content and store it in a variable. Then, you must pass the variable’s value to the general file. For example:

dim content, NFiles, aux, aux1, fso, f
Const ForReading = 1, ForWriting = 2

content = “”

‘number of files:
NFiles = 4

‘reads each file
for i=1 to NFiles

Set fso = CreateObject(“Scripting.FileSystemObject”)
Set f = fso.OpenTextFile(“file”& i & “.txt”, ForReading)
content = content & f.ReadAll & vbNewLine & “**********************” & vbNewLine

next

‘Creates the “General File” (if it already exists, erase the file)
Set aux = CreateObject(“Scripting.FileSystemObject”)
Set aux1 = aux.CreateTextFile(“generalfile.txt”, True)
aux1.Close

‘Writes all content in the GeneralFile
Set aux = CreateObject(“Scripting.FileSystemObject”)
Set aux1 = aux.OpenTextFile(“generalfile.txt”,8)
aux1.WriteLine content
aux1.Close

In this example, we are using ordered files with similar names so that the “for/next” clause works properly:
file1.txt
file 2.txt
file 3.txt
…For more details, check the attached sample application developed with E3 version 3.2 build 260.

Attachments:

GroupTXTFiles_en.zip

 

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *