Page 1 of 1

[Solved] In what order do files get joined?

Posted: 05 Mar 2020 08:15
by iycgtptyarvg
I have this script (I think I got it from someone on this forum):

Code: Select all

//Combine selected files in order
"Concatenate Files"
	$itemCount = get("CountSelected");
	if ($itemCount < 2){
		msg "Please select two or more files to concatenate.", 0 + 48;
	}
	else {
		//No modifier keys pressed - use defaults
		$outputFileExt = getpathcomponent("<selitem>", "ext");
		
		//Initialise variables used in loop
		$outputFilePath = <curpath> . "\" . <date yyyy-mm-dd-hh-mm-ss> . ".$outputFileExt";
		$index = 0;

		//Process files
		foreach($token, <get selecteditemspathnames |>) {
			$index = $index + 1;
			$fileContent = readfile("$token");
			writefile("$outputFilePath", $fileContent, "a");
		}
		status "Concatenated file generation complete - $outputFilePath";
	}
I'm afraid to use this when the order of joining matters. Is there a GUARANTEED order? For instance, always alphabetically, or always in the order how it is displayed in the file list, or maybe depending on how you drag select the files (top to bottom, or bottom to top), or maybe in which order you <CTRL>-clicked them?

Does someone know 100% sure?

Re: In what order do files get joined?

Posted: 05 Mar 2020 08:49
by highend
There is no guaranteed order but you are free to create it yourself by e.g using
an inputselect with 16+512 flags...

Re: In what order do files get joined?

Posted: 05 Mar 2020 09:15
by iycgtptyarvg
Unfortunately, I don't know how to do that.
Could you please alter the script to have the guaranteed order HOW IT IS DISPLAYED IN THE FILES LIST?

Re: In what order do files get joined?

Posted: 05 Mar 2020 09:30
by highend
Just to make this 100% sure, you want the selected items in that order how the current list displays them.

E.g. these 4 files are selected and the list is sorted by name ascendingly:

Code: Select all

Dbg.pbi
Math.pbi
Process.pbi
ScanDir.pbi
You would join them in that order.

If you would now change the sort order for the name column from ascending to descending and the displayed items would change too:

Code: Select all

ScanDir.pbi
Process.pbi
Math.pbi
external
Dbg.pbi
You would want them to be joined in this new order regardless how they were selected? In that case there is no need for a change,
<get selecteditemspathnames |> uses the displayed order from the list...

It would be different if e.g. <drop> would be used...

Re: In what order do files get joined?

Posted: 05 Mar 2020 10:57
by iycgtptyarvg
Ok, so to make this 100% clear.

How it is now will join in VISIBLE ORDER, regardless how I selected it and which is the 'focused' item?

Re: In what order do files get joined?

Posted: 05 Mar 2020 11:46
by highend
Yep

Re: [Solved] In what order do files get joined?

Posted: 05 Mar 2020 13:41
by iycgtptyarvg
Thank you, thank you, thank you.

I marked it [Solved].