I get error
"Subscript Range in access or evaluation of 'openDTs[ /*###*/1]' , openDTs[/*###*/1]"
but it works on some folder and I don't get the error...Below is my JSL
JSL "
dir = Set Default Directory("path");
Print(dir);
files = Files In Directory("path");
For(i = 1, i <= N Items(files), i++,
If(Ends With(files[i], ".txt"),
Open(
files[i],
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")
)
)
)
);
openDTs = List();
For(i = 1, i <= N Table(), i++,
Insert Into(openDTs, Data Table(i))
);
For(i = 1, i <= N Items(openDTs), i++,
openDTs[i] << New Column("Location", Character, Nominal, Set Each Value(dir));
openDTs[i] << New Column("FileName",
Character,
Nominal,
Set Each Value(openDTs[i] << Get path)
);
);
openDTs1 = openDTs[1];
Remove From(openDTs, 1);
Joined_new = openDTs1 << concatenate(openDTs, output table name("Joined_new"));
"
Don't I need to define "i"..I get Name unresolved for i...

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(files[i], ".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"));
);