Could it be that some of your folders have no files which could be turned into data table and openDTs is empty list?
Edit:
You can add check and stop if no tables have been opened. I made slight modifications to your script but the idea should still be the same with the exception of final checks after the the loop (requires JMP16+) and it assumes you want to only use tables which are found from your directory
Names Default To Here(1);
dir = Set Default Directory("path");
files = Files In Directory("path");
dts = {};
For Each({filepath}, files,
If(Ends With(filepath, ".txt"),
dt = Open(
filepath,
Import Settings(
End Of Line(CRLF, CR, LF),
End Of Field(Comma),
Strip Quotes(0),
Use Apostrophe as Quotation Mark(0),
Scan Whole File(1),
Labels(0),
Column Names Start(1),
Data Starts(1),
Lines To Read(All),
Year Rule("10-90")
)
);
dt << New Column("Location", Character, Nominal, Set Each Value(dir));
dt << New Column("FileName", Character, Nominal, Set Each Value(dt << Get path));
Insert Into(dts, dt);
);
);
If(N Items(dts) == 0,
stop(); // stop here as no tables have been created
, N Items(dts) == 1,
dt_final = dts[1]; // only one table
, // else - more than one table
dt_first = Remove From(dts, 1)[1]; // Remove From returns a list -> take first index
dt_final = openDTs1 << concatenate(dts, output table name("Joined_new"));
);
Edit 2: Fixed Open(files[i] to Open(filepath
Edit 3: Fixed openDTS1 to dt_first
-Jarmo