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

Author Topic: need help: How to write a batch to combine more 100 text files to one text file?  (Read 16415 times)

0 Members and 1 Guest are viewing this topic.

billrich



    Rookie

    Thanked: 1
    Hey bill, try reading next time.

    I meant to say I could not get the following code to work on my machine:

    @echo off
    for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

    The solutions offered here on the Hope Board are not just for the Original poster.  Many readers can often use the information.

    I wonder if Helpme can show us the output for:

    @echo off
    for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

    Must we offer a new "ENDNUMBER" each time we run the code?

    I use XP.  Will the above code run for XP?

    An example of the Output of all code offered will help the OP plus the readers.

    Thank you Helpmeh  for your time and effort.



    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    You replace ENDNUMBER with the number in the last file. The OP perfectly understood, and it seemed very obvious to replace it.
    And no, I can not run it, as I am not on a computer.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    ghostdog74



      Specialist

      Thanked: 27
      what bill (or joan or liz or mike or ??) meant is OP won't know the ENDNUMBER before hand unless he can find out from dir *.txt and change the code. Its probably better not to use the for loop range + step method, but just use the output from dir file*.txt
      Code: [Select]
      for .... (dir file*.txt) do (
        type .... >> output.txt
      )

      BatchFileBasics



        Hopeful

        Thanked: 18
        how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank

        replace the "set I=1" for the number the file sequence starts

        Code: [Select]
        @echo off
        :recurse
        set I=1

        cd
        FOR /f "tokens=*" %%P IN ('dir /A-d /b *.txt') do (call :showfiles "%%P")
        echo.
        echo Filecount: %I%

        for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt
        :showfiles
        echo %1
        set /a I+=1
        goto :eof
        When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

        ghostdog74



          Specialist

          Thanked: 27
          how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank

          replace the "set I=1" for the number the file sequence starts

          Code: [Select]
          @echo off
          :recurse
          set I=1

          cd
          FOR /f "tokens=*" %%P IN ('dir /A-d /b *.txt') do (call :showfiles "%%P")
          echo.
          echo Filecount: %I%

          for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt
          :showfiles
          echo %1
          set /a I+=1
          goto :eof

          why not just do dir file*txt ? there's no need to call another loop to count total files. Of course, unless there other files with names like filetest.txt , fileblahblah.txt and you want to isolate those that have numbers following "file", which you could do that with dir file*txt | findstr /I "file[0-9]*.txt"

          billrich



            Rookie

            Thanked: 1
            how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank

            replace the "set I=1" for the number the file sequence starts

            Code: [Select]
            @echo off
            :recurse
            set I=1

            cd
            FOR /f "tokens=*" %%P IN ('dir /A-d /b *.txt') do (call :showfiles "%%P")
            echo.
            echo Filecount: %I%

            for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt
            :showfiles
            echo %1
            set /a I+=1
            goto :eof


            Where is Output?

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8

            Where is Output?
            Why don't YOU run it and put out any output it makes, instead of "Where is output?" over and over again. Sometimes you really sound like a broken record.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            Salmon Trout

            • Guest
            Why don't YOU run it and put out any output it makes, instead of "Where is output?" over and over again. Sometimes you really sound like a broken record.

            I don't think I would have bought that record in the first place, let alone played it after it was broken. Anyhow, wasn't he banned? Why is he now unbanned?

            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            I don't think I would have bought that record in the first place, let alone played it after it was broken. Anyhow, wasn't he banned? Why is he now unbanned?

            New name...lowercase b is all it takes.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            billrich



              Rookie

              Thanked: 1
              New name...lowercase b is all it takes.

              -------------------------------------

              Show your code and show output and stop faking it.
              « Last Edit: December 16, 2009, 04:27:44 PM by Fed »

              Helpmeh



                Guru

              • Roar.
              • Thanked: 123
                • Yes
                • Yes
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 8
              -------------------------------------

              Show your code and show output and stop faking it.
              1. I've shown my code, heck, YOU've even used it in your posts.
              2. As I've said before, I don't have access to a computer. I am on my iPod.
              3. How am I faking? Read the OP's post. The code worked great for him.
              Where's MagicSpeed?
              Quote from: 'matt'
              He's playing a game called IRL. Great graphics, *censored* gameplay.

              billrich



                Rookie

                Thanked: 1
                Read the OP's post. The code worked great for him.

                The problem is on my end.  I could not get the code to work on my machine.
                I thought I could look at your code and output  and figure what I was doing wrong.

                @echo off
                for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

                I might try again.

                Helpmeh



                  Guru

                • Roar.
                • Thanked: 123
                  • Yes
                  • Yes
                • Computer: Specs
                • Experience: Familiar
                • OS: Windows 8
                The problem is on my end.  I could not get the code to work on my machine.
                I thought I could look at your code and output  and figure what I was doing wrong.

                @echo off
                for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

                I might try again.

                Did you change ENDNUMBER? You haven't posted anything but a copypasta of my code. Post the code in YOUR batch file.
                Where's MagicSpeed?
                Quote from: 'matt'
                He's playing a game called IRL. Great graphics, *censored* gameplay.

                BatchFileBasics



                  Hopeful

                  Thanked: 18
                  When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                  Helpmeh



                    Guru

                  • Roar.
                  • Thanked: 123
                    • Yes
                    • Yes
                  • Computer: Specs
                  • Experience: Familiar
                  • OS: Windows 8
                  I think bill is just frustrated because the code doesn't work for him. That happens to the best of us. We get impatient and angry.
                  Where's MagicSpeed?
                  Quote from: 'matt'
                  He's playing a game called IRL. Great graphics, *censored* gameplay.