Click here to Skip to main content
15,886,199 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced4-May-09 5:38
riced4-May-09 5:38 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24824-May-09 20:51
vijay24824-May-09 20:51 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced4-May-09 22:04
riced4-May-09 22:04 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24824-May-09 22:26
vijay24824-May-09 22:26 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced4-May-09 22:44
riced4-May-09 22:44 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24824-May-09 22:56
vijay24824-May-09 22:56 
GeneralMessage Closed Pin
4-May-09 23:14
vijay24824-May-09 23:14 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 0:30
riced5-May-09 0:30 
vijay2482 wrote:
If the header is found again in the next file


Does this mean that there may not be a header in a file? Or should it be When the header is found?
In the first case (i.e. IF) then you have no guarantee that the first file read will contain a header so you need to do something like this.
Dim theDir As DirectoryInfo = new DirectoryInfo(iFile);
Dim datFiles As FileInfo()  = theDir.GetFiles("*.txt");

Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
  'Write the header lines to output file
   For Each fi As FileInfo In datFiles
      Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
         'read line from input
         If 'header line' Then
            'Skip it
         Else
            'write to output
         End If
      End Using
   Next
End Using

You can write the header either by reading a special header.txt file that only contains header lines (and is not in the folder you're searching) or by hard coding the text as strings. The first way is better because if the headers change you don't need to change the code just the txt file.

If it's the second case (i.e. all files have header, you could do something like this.
Dim theDir As DirectoryInfo = new DirectoryInfo(iFile);
Dim datFiles As FileInfo()  = theDir.GetFiles("*.txt");

Using sw As StreamWriter = New StreamWriter(oFile, True, System.Text.Encoding.Default)
   Dim skipHeader as Boolean = False
   For Each fi As FileInfo In datFiles
      Using sa As StreamReader = New StreamReader(fi.FullName, System.Text.Encoding.Default)
         'read input line 
          If 'header line' And Not skipHeader Then
             'write output line - first line of header
             'read input line   - second line of header
             'write output line
             skipHeader = True
          Else
             'write output line
          End If
      End Using
   Next
End Using

Note that this assumes there's only one or two header lines.
Note also that this is pseudocode mixed with VB not pure VB.

There's two problems with this
vijay2482 wrote:
if name.contains("Nom du Modéle") or if name.contains("----") then
else
'read and write
End If

1 You don't need the second if.
2 When you find a header you still need to do a read, the best way is to do the read then the test for header as in the two bits I've done.

Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis

GeneralMessage Closed Pin
5-May-09 1:45
vijay24825-May-09 1:45 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 2:30
riced5-May-09 2:30 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 1:18
riced5-May-09 1:18 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 1:59
vijay24825-May-09 1:59 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 2:12
riced5-May-09 2:12 
GeneralMessage Closed Pin
5-May-09 4:04
vijay24825-May-09 4:04 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 6:47
riced5-May-09 6:47 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 10:24
vijay24825-May-09 10:24 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile [modified] Pin
vijay24825-May-09 21:29
vijay24825-May-09 21:29 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 22:08
riced5-May-09 22:08 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 22:40
vijay24825-May-09 22:40 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 23:02
vijay24825-May-09 23:02 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
riced5-May-09 23:35
riced5-May-09 23:35 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24825-May-09 23:53
vijay24825-May-09 23:53 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
vijay24826-May-09 0:08
vijay24826-May-09 0:08 
GeneralRe: Append ALL Textfiles within a folder to a Single Textfile Pin
Dave Kreskowiak4-May-09 4:07
mveDave Kreskowiak4-May-09 4:07 
QuestionCOM port Pin
Subjugate3-May-09 21:07
Subjugate3-May-09 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.