CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2002
    Location
    zimbabwe
    Posts
    13

    read and append text file details to onother text file

    i have three text files and i want to read staff from the other two and append it to one .how do i do it??

    when opportunities arises ,only the prepared mind is fovoured

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: read and append text file details to onother text file

    Try this...

    Dim FFileIn as Long, FFileOut as Long

    FFileOut = FreeFile
    Open "c:\output.txt" for Output as #FFileOut

    FFileIn = FreeFile
    Open "c:\input1.txt" for input as #FFileIn
    print #FFileOut, input(FileLen("c:\input1.txt"),FFileIn)
    Close #FFileIn

    FFileIn = FreeFile
    Open "c:\input2.txt" for input as #FFileIn
    print #FFileOut, input(FileLen("c:\input2.txt"),FFileIn)
    Close #FFileIn

    FFileIn = FreeFile
    Open "c:\input3.txt" for input as #FFileIn
    print #FFileOut, input(FileLen("c:\input3.txt"),FFileIn)
    Close #FFileIn

    Close #FFileOut



    This will read the content of input1.txt, input2.txt and input3.txt and write it to output.txt

    Tom Cannaerts
    slisse@planetinternet.be.remove.this.bit
    Moderator on http://www.vbcodelibrary.co.uk/board

    A bottomless pit, I'm sure it came with the place, who would dig one on purpose?
    Tom Cannaerts
    email: cakkie@cakkie.be.remove.this.bit
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jun 2002
    Location
    Baltimore, Md USA
    Posts
    22

    Appending Text Files

    I came across this thread in a search. I also need to append several text files into one text file. This codes works very well.

    My questions:
    - Instead of hardcoding the filenames, how do I just specify a certain directory where the input files are located?
    - If I just use the directory, I want to be able to vary the number of files.

    Any help will be appreciated.

    SB

  4. #4
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    To use non-static folder and filename, as an example, use variable:

    Change:
    Open "c:\input1.txt"

    For:
    strFolderName = "C:\"
    strFileName = "input1.txt"
    Open strFolderName & strFileName


    If you want to return all the files from a specific folder, you can do it two ways, first by using DIR() function, second by using FileSystemObject :

    Code:
    'Add a reference to Microsoft Scripting Runtime
        Dim fso As new FileSystemObject
        Dim objFolder As Folder
        Dim objFile As File
    
        'Get the folder you want, can be "C:\"
        Set objFolder = fso.GetFolder(strFolderName)
    
        'Browse each files in the folder
        For Each objFile In objFolder.Files
             'Do your stuff here
        Next
    JeffB

  5. #5
    Join Date
    Jun 2002
    Location
    Baltimore, Md USA
    Posts
    22
    Thanks Jeff B - this works great!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured