Ordering Files in FolderFolks,
I have a list of files that I want to concatenate (see first figure). The preference would be to concatenate as shown, that is "surf_12275-87-1..., "surf_12275-87-2...", etc. However, when I form a list from the files in the folder (after stripping off unnecessary characters) , the sequence is "12275-87-1, 12275-87-10, 12275-87-11". The preference however, would be "12275-87-1, 12275-87-2, 12275-87-3". Obviously the straight forward way around the issue is to have the files come to me in the form of " -01, -02, ... -10, -11", but that will not always be the case.
Is there a straight forward way to get the files into the preferred ranking format so I can open and concatenate from low to high? Current script attached.
s_path = {};
X_path = {};
f1 = Files In Directory( SD1, recursive(1));
For( i = 1, i <= N Items( f1 ), i++,
b = f1[i];
c = Contains Item(b, "surf", "_");
If( c==1,
d = Word(2, b, "_");
Insert Into(s_path,d),
Insert Into(X_path, d)
)
);
Show(s_path);


ScriptingRe: Ordering Files in FolderJMP data table seem to be using numerical sorting if you have columns modeling type as ordinal so you could use that or for loop.
Names Default To Here(1);
a = {
"surf_12275_87-1_r250",
"surf_12275_87-2_r250",
"surf_12275_87-3_r250",
"surf_12275_87-4_r250",
"surf_12275_87-5_r250",
"surf_12275_87-6_r250",
"surf_12275_87-7_r250",
"surf_12275_87-8_r250",
"surf_12275_87-9_r250",
"surf_12275_87-10_r250",
"surf_12275_87-11_r250",
"surf_12275_87-12_r250",
"surf_12275_87-13_r250",
"surf_12275_87-20_r250",
"surf_12275_87-22_r250"
};
a = Sort List(a); //break the ordering
Show(a);
dt = New Table("",
New Column("SortList", Character, Ordinal, Set Values(a)), private
);
dt << Sort(By(:SortList), Order(Ascending), Replace Table);
b = dt:SortList << Get Values;
Close(dt, no save);
Show(b);
c = {};
For(i = 1, i <= N Items(a), i++,
Insert Into(c, a[i], Num(Words(a[i], "-_")[4]));
);
Show(c);These could give some idea how to approach the problem.
Re: Ordering Files in FolderJarmo,
Many thanks for teaching me a new skill set. I've tried all your suggested approaches to improve my coding ability. Here is my latest revision which does exactly what I want.
Thank you again
Neil
f1 = Files In Directory( SD1, recursive(1));
f1 = Sort List(f1);
dt = New Table("",
New Column("SortList", Character, Ordinal, Set Values(f1)), private
);
dt << Sort( By(:SortList), Order(Ascending), Replace Table);
b = dt:SortList << Get Values;
Close(dt, no save);
For( i=1, i <= N Items(b), i++,
file_1 = Open(SD1 || b[1]);
If(i > 1,
file_nxt = Open(SD1 || b[i], Private);
file_1 << Concatenate(file_nxt, Append to first table);
)
);
file_1 << Save(SD1 || "All Summary");Re: Ordering Files in FolderJim,
I can't tell you how insightful this approach was for another (unrelated to this thread) problem I was having. That is, file names with unpredicted "element" arrangements. At least I'm able to dissect the filenames and "reorder" to consistent labeling.
Thanks again for all your help.
Neil