Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Joining Text Files

  • 02-07-2002 12:53PM
    #1
    Closed Accounts Posts: 1,092 ✭✭✭


    Does anyone know of a simple program that can join (concatenate) a series of *.txt into one large *.txt files and then automatically delete the original *.txt files leaving only one single file? I'm aware there is a command at the dos prompt that will do this but as far as I know it will only connect two files at a time and will not delete the original files afterwards.

    Any suggestions are gratefully recieved.


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    A small .bat file should do it. I haven't written one in quite some time, but something along the lines of :

    [conc.bat]
    <doscommand> %1 %2
    erase %2
    conc %1 %3
    

    That should *roughly* do it. I'm not sure what DOS command sticks two files together, probably append or something?

    Anyway, this only accepts 3 filenames (obviously it could be changed to accept more), and I'm not sure if batch files can do recursion, and I'm assuming that the second gets added to the first but you get the idea.

    Check out something on writing batch files - if you can reference all of the unused command-line variables in one go, then that last line can be changed to allow you to stick together as many files as you want.

    Batch files can be handy if you use Dos a lot. For example, I kept using 'ls' instead of 'dir' (damn Linux :p), so I just wrote a little batch file called ls.bat, that picks up on when I make this mistake, and does its function, instead of having DOS moan at me. It'll also accept a couple of arguments :)


  • Closed Accounts Posts: 286 ✭✭Kev


    the dos command to concatenate files is copy


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Originally posted by Kev
    the dos command to concatenate files is copy

    he's right ya know, but it asks for the destination filename after the sources, which may cause hassle, so we'll to write it unix style (destination first) :p
    :
    copy %2+%3+%4+%5+%6+%7 %1
    erase %2 %3 %4 %5 %6 %7
    

    So this will take up to 6 files and concantenate them. Just make sure you put the destination first.

    [But oh look, seeing as copy will already stick together an arbitrary no. of files, this makes my batch file irrelevant :D

    One of the first rules of programming: don't go reinventing the wheel :D n1 Kev.


Advertisement