Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ho do I open each file in a folder and append the contents on separate lines in a new file?

Posted on 2008-09-30
2
Medium Priority
?
248 Views
Last Modified: 2012-05-05
I have several files in  a folder with one line in each of them. I want each lines put into one file appended after each other. Then I want to move the original file(s) to an archive folder. I am using VB.NET 2003. Do you have some code examples how to accomplish this? Thank you.
0
Comment
Question by:IT_Steve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 22610302
It might look something like...
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sb As New System.Text.StringBuilder
        Dim outputFile As String = "c:\output.txt"
        Dim sourceFolder As String = "c:\data"
        Dim archiveFolder As String = "c:\archive"
        For Each file As System.IO.FileInfo In New System.IO.DirectoryInfo(sourceFolder).GetFiles("*.txt")
            sb.Append(ReadEntireFile(file.FullName))
            file.MoveTo(System.IO.Path.Combine(archiveFolder, file.Name))
        Next
        Dim sw As New System.IO.StreamWriter(outputFile)
        sw.Write(sb.ToString)
        sw.Close()
    End Sub
 
    Private Function ReadEntireFile(ByVal filename As String)
        Dim sr As New System.IO.StreamReader(filename)
        Dim entireFile As String = sr.ReadToEnd
        sr.Close()
        Return entireFile
    End Function
 
End Class

Open in new window

0
 

Author Closing Comment

by:IT_Steve
ID: 31501759
I wish I could make this stuff fluent for me like it seems for you. I guess I just keep at it. Seeing it makes it pretty clear.Thanks again for your assistance.
Steve
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question