Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Combining multiple files into one file....  (Read 4614 times)

0 Members and 1 Guest are viewing this topic.

dkennelly

    Topic Starter


    Rookie

    Combining multiple files into one file....
    « on: May 19, 2010, 04:15:23 PM »
    How can I combine the below multiple files into one file using the copy command?

    Acks20100506200212.txt
    Acks20100506210105.txt
    Acks20100511190103.txt
    Acks20100511200230.txt

    The filenames change everyday with yyyymmdd and six random numbers.  The destination file will be named acks.txt.

    Computer_Commando



      Hacker
    • Thanked: 494
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10

    dkennelly

      Topic Starter


      Rookie

      Re: Combining multiple files into one file....
      « Reply #2 on: May 19, 2010, 04:48:08 PM »
      I read the help already.  My issue is the filenames....

      To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format).

      How do I do this with the files that I have listed?  I can't use acks*.* to combine all the files can I?  I basically only know that they they will begin with acks.  So how do I combine them...would I use COPY or FOR. ;D

      dkennelly

        Topic Starter


        Rookie

        Re: Combining multiple files into one file....
        « Reply #3 on: May 19, 2010, 05:03:24 PM »
        Ahhh...I see.  The copy command works but when I look at the destination file it is combining on the same line instead of starting the next file on the next line...how do I fix that? ;D

        dkennelly

          Topic Starter


          Rookie

          Re: Combining multiple files into one file....
          « Reply #4 on: May 19, 2010, 05:06:51 PM »
          It's amazing what you can learn when you read. ;D

          I got it figured out.....thank you for your help.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Combining multiple files into one file....
          « Reply #5 on: May 19, 2010, 05:14:52 PM »
          The ideal solution would he to append the new files to the master file you already have. However, there may be a problem if you do not know the exact names of the files.

          Before writing code, it is wise to examine the pitfalls and problems you could get into. We shall assume that you have an application that absolutely requires you merge all these files into one big file. That is seldom needed, but we will assume that in your case it is needed.

          You need to resolve the issue of identifying which files are new and what is the exact name of the file. You mentioned that part of the file name would be random.

          Does the application that creates the files set the  archive bit so that you will know that the file is ready to be archived? If so, then any new files in the that particular directory need to be added or upended to the master file. And after done the files need to have archive bit get set to indicate the files are no longer new files in the sense that they've are ready been merged into the master file.

          Now if something goes wrong, do you have a way of figuring out how to do this manually, if necessary? A common problem in managing large amounts of data is that nobody figures out how to recover from my catastrophic error. Have you given thought to that?

          This is not one of my usual sarcasms, rather I am assuming that you area IT professional and have a serious need to store a lot of log files or something like that into a large master-file.

          Yes, a FOR loop could be used to at the end all the new files to a masterfile. You may wish to consider a method where first you would make a backup of the master-file and then start a painting to the original master-file. If something goes wrong, you have a backup copy copy of the master-file before new stuff was added to it.
          Once you specify exactly what you want the system to do, then you can write an appropriate batch file that will do the job for you with a rather simple FOR loop.


          marvinengland



            Hopeful

            Thanked: 11
            Re: Combining multiple files into one file....
            « Reply #6 on: May 19, 2010, 05:34:35 PM »
            How can I combine the below multiple files into one file using the copy command?

            Acks20100506200212.txt
            Acks20100506210105.txt
            Acks20100511190103.txt
            Acks20100511200230.txt

            The filenames change everyday with yyyymmdd and six random numbers.  The destination file will be named acks.txt.


            C:\test>type  ken.bat

            Code: [Select]
            @echo off

            set MM=%date:~4,2%
            set DD=%date:~7,2%
            set YYYY=%date:~10,4%
            echo MM=%MM%
            echo DD=%DD%
            echo YYYY=%YYYY%

            set ran=%random%
            set ran=%random%66
            set ran=%ran:~0,6%

            echo ran=%ran%

            echo hello > acks%yyyy%%mm%%dd%%ran%.txt
            type acks%yyyy%%mm%%dd%%ran%.txt  >> acks.txt
            dir acks*.txt

            C:\test>ken.bat
            MM=05
            DD=19
            YYYY=2010
            ran=323236
             Volume in drive C has no label.
             Volume Serial Number is 0652-E41D

             Directory of C:\test

            05/19/2010  06:24 PM                32 acks.txt
            05/19/2010  06:24 PM                 8 acks20100519144326.txt
            05/19/2010  06:24 PM                 8 acks20100519164486.txt
            05/19/2010  06:24 PM                 8 acks20100519297006.txt
            05/19/2010  06:24 PM                 8 acks20100519323236.txt
                           5 File(s)             64 bytes
                           0 Dir(s)  295,305,261,056 bytes free



            C:\test>dir acks*
             Volume in drive C has no label.
             Volume Serial Number is 0652-E41D

             Directory of C:\test

            05/19/2010  06:54 PM                32 acks.txt
            05/19/2010  06:24 PM                 8 acks20100519144326.txt
            05/19/2010  06:24 PM                 8 acks20100519164486.txt
            05/19/2010  06:24 PM                 8 acks20100519297006.txt
            05/19/2010  06:24 PM                 8 acks20100519323236.txt
                           5 File(s)             64 bytes
                           0 Dir(s)  295,304,232,960 bytes free

            C:\test>
            Code: [Select]
            type  acks2010*  >>  acks.txtacks20100519144326.txt



            acks20100519164486.txt



            acks20100519297006.txt



            acks20100519323236.txt



            C:\test>type acks.txt
            hello
            hello
            hello
            hello

            C:\test>
            « Last Edit: May 19, 2010, 05:55:23 PM by marvinengland »
            USA

            dkennelly

              Topic Starter


              Rookie

              Re: Combining multiple files into one file....
              « Reply #7 on: May 24, 2010, 12:58:15 PM »
              Works great Marvin ;D Thanks!