Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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,317 ✭✭✭✭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,317 ✭✭✭✭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