The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Change Findfiles Sorting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

parcomilati

6 Posts

Posted - 11/09/2022 :  12:21:44 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi everybody,
I have a problem with the way findfiles collects the names of the files in the given folder. In particular, three files named file_1, file_2, and file_10 will be collected in the following order:

file_1
file_10
file_2

which I think is alphabetical order of collection. This is problematic since I'd like to have my file imported like:

file_1
file_2
file_10

so a more numerical-like order.
Are there any options in findfiles or procedures that I can use to sort those files in the way I prefer?
Thank you so much.
Marco

YimingChen

1683 Posts

Posted - 11/09/2022 :  2:00:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can extract the file index from the file name, sort the indices and reorder the files. See the example code below:

string files = "file_1%(CRLF)file_10%(CRLF)file_2";
int n = files.GetNumTokens(CRLF);
Dataset ids;
ids.SetSize(n);
for (int i = 1; i <= n; i++) {
	string file = files.GetToken(i, CRLF)$;
	string strFileIndex = file.GetToken(2, '_')$;
	int index = strFileIndex.value();
	ids[i] = index;
}
ids = sort(ids);
for (int i = 1; i <= n; i++) {
	string file = "file_$(ids[i])";
	type %(file$); 
}


James
Go to Top of Page

aplotnikov

Germany
170 Posts

Posted - 11/10/2022 :  03:16:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The best way is to rename your files (file_X -> file_0X, X=1..9) using cmd commands in a batch-file:

@echo off
SETLOCAL EnableDelayedExpansion
for %%f in (file_?.) do (
set _fff=%%f
ren !_fff! !_fff:~0,5!0!_fff:~5!
)

Edited by - aplotnikov on 11/10/2022 06:15:25 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000