combining multiple txt files into one

Shane's icon

I am working on a patch that creates multiple text files using textedit and the text object. These text files are saved with filenames like "x_1.txt," "x_2.txt," and so on.

Is it possible, in Max, to combine all of these text files into a single txt?

Basically, I'd like to add an "export all" button that, when pushed, will take all existing files and compile them sequentially into a new "x_all.txt" file.

Can I do this by reading them all into [text] or some other object?

Thanks!

Source Audio's icon

if you want only plain max solution,

use one text to read and dump into other one that merges them all.

Shane's icon

Thanks! I was able to figure out a way of doing it (probably not very elegant)...

combine-txt-files.maxpat
Max Patch

Right now I am using [combine] to name the files according to the name of a video ("currentvideo") followed by an underscore and a number [combine s i . txt]. But this fills up the folder where I am working. I'd like to specify a subfolder (or let the user specify a subfolder), but I keep running into problems: If I use [opendialog fold], I can pass it to [absolutepath], but then I have quotation marks, which I can remove with [fromsymbol]. But if I then send the path via [send], and pass it to [combine s s i . txt] it sometimes eliminates spaces (my hard drive is "Macintosh HD:" and this gets shortened to "MacintoshHD:"). I'm sure this is a total beginner problem, but any pointers would be much appreciated!

Source Audio's icon

I am soon to leave the house.

Will take a look as soon as possible and report back.

Source Audio's icon

had a short lo0k,

sorry but it looks a bit chaotic.

I would drop folder with text files, build

umenu with paths,

set folder to write,

read text files one by one,

write merged file at end.

Shane's icon

Haha, chaotic yes! (I am a total newbie and muddling my way through...)

Thanks for these suggestions. I am trying to avoid using dropfile, because I want the option to create a new folder (opendialog fold lets the user choose a folder that doesn't yet exist).

I appreciate these tips!

Shane's icon

I hate to ask, but I wonder if you could take another look at this patch and tell me if you can see why the final text file doesn't get appended when exporting them all together? (I have a folder with 75 txt files, and I am combining them into one; files 1 to 74 all show up, but number 75 is missing. I have tested with only 4 files, and similarly files 1 to 3 are copied into the new txt file, but number 4 is missing).

I know this is embarrassingly messy, and probably not the ideal approach, but I simply can't wrap my head around why the text of the last file doesn't get copied over.

Appreciate any tips! Thanks in advance!

export-all-files.maxpat
Max Patch

Source Audio's icon

Could you please upload you patchers as "copy -compressed" ones ?

So one does not need to download them.

Your patch does not have essential stuff included.

Only send - receive of unknown whatever.

look at this example that I mentioned yesterday.

it asks where to store when dump of all text files is done

Max Patch
Copy patch and select New From Clipboard in Max.

Shane's icon

Sorry, I didn't see this until now, and sorry for posting the patches wrong (I'll look into the proper way). Your patch was really helpful in understanding some basic concepts for this, and I am looking at how to change my approach. So I'll see how it develops before posting, but thanks, once again, for your help! It's much appreciated.

Source Audio's icon

If you need any further help, like

how to extract parts of the path, or combine strings into usable path

or anything else just post