Join command FROM subfolders

The Join command has a FROM argument where I can list the files that I want to concatenate. I can use D:\thisfolder\*.sql to make it use the implicit list of the files in that folder but I need all the files under that folder's subfolders. Can this be done without scripting?

I am afraid only if you use Flat View or a collection and a button like

 Join TO=D:\joined.txt FROM {allfilepath}
1 Like

It's easy enough to do with scripting:

function OnClick(clickData)
	var cmd = clickData.func.command;
	cmd.deselect = false;

	var pattern = /\.sql$/i; // Match *.sql files.

	var folderEnum = DOpus.FSUtil.ReadDir(clickData.func.sourcetab.path);
	while (!folderEnum.complete)
		var folderItem = folderEnum.Next();
		if (!folderItem.is_dir) continue;
		var subEnum = DOpus.FSUtil.ReadDir(folderItem);
		while (!subEnum.complete)
			var subItem = subEnum.Next();
			if (subItem.is_dir || !(subItem+"").match(pattern)) continue;
		//	DOpus.Output(subItem);

	if (cmd.files.count == 0) return;
1 Like

Thank you very much, Leo!

I'm almost there. I altered the script to work with folder hierarchy arbitrarily deep, but I have a serious problem. Before, when I used Flaw View, the files were passed to Join in the order they were in the lister, and the lister had "Numeric order filename sorting" enabled. However, the script method adds the file to the command in a different order. I've tried adding them to an array first (named files) and then applying sort on that array:

files.sort(function(a, b) {return a.localeCompare(b, undefined, {numeric: true});});

but this didn't work either. The order is still not good eg.:

whatever_V0.49.131__another file

The lister puts these files in the order I'd expect them to be, the sort function does not. And I suspect it couldn't, I guess the numeric ordering DOpus uses is a bit more sophisticated. Any hints on how to achieve my goal (if it is even possible)?

The script could turn on Flat view and enumerate tab.files. Just an idea, but I'd be optimistic.

I've already figured how to make it work through enabling Flat view, and it doesn't even require scripting. However, it switches current folders for both left and right tabs, sets Flat view, selects and deselects files, that is, it generally ruins my tab setup for the project, and I have to restore them after. So Leo gave me an idea, that with scripting I might get things done without ever having to switch folders or turn on/off Flat view. I've just run into this annoying file sorting issue...

You could run everything in a duplicated tab, maybe even in a new lister (and kill them later).

I am looking forward to the day when the vector sort method receives an update to sort a vector's elements more than just alphabetically :slight_smile: