Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Combining all files in single file

Combining all files in single file

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    learningvisualc
    wrote on last edited by
    #1

    Hi all, i want to combine all my files into a single file. How can i do it. Thanks in advance

    _ A 2 Replies Last reply
    0
    • L learningvisualc

      Hi all, i want to combine all my files into a single file. How can i do it. Thanks in advance

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You can do this from the command prompt using the command copy *.* newfile. To do this programatically, open the destination file for writing using CreateFile. Use FindFirstFile / FindNextFile to enumerate each file in the folder. For each file found use CreateFile to open the file for reading. Call ReadFile to read the entire contents of the file for reading and then use WriteFile on the destination file to write the contents that were read.

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • L learningvisualc

        Hi all, i want to combine all my files into a single file. How can i do it. Thanks in advance

        A Offline
        A Offline
        Aescleal
        wrote on last edited by
        #3

        If you're using C++ you can combine files fairly easily. Open each one as an istream, open the destination file as an ofstream and then insert the streambufs of the input files to the destination file. Something like:

        std::ifstream a( "c:\\\\a.txt" );
        std::ifstream b( "c:\\\\b.txt" );
        
        std::ofstream c( "c:\\\\c.txt" );
        c << a.rdbuf() << b.rdbuf();
        

        will concatenate a.txt and b.txt and dump them in c.txt. It saves loads of tedious mucking about with C functions or Windows API functions. Cheers, Ash

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups