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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Change Findfiles Sorting

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
parcomilati Posted - 11/09/2022 : 12:21:44 PM
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
2   L A T E S T    R E P L I E S    (Newest First)
aplotnikov Posted - 11/10/2022 : 03:16:41 AM
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!
)
YimingChen Posted - 11/09/2022 : 2:00:55 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000