LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort File path x.x.x

Solved!
Go to solution

Looking for the forum thread on sorting strings/file paths of the numeric format x.x.x.x

(where the number of x's was probably known) and there was a requirement to sort them.

I thought it would be faster to find the thread with the good code than try to re-engineer some inferior code myself.

(trying to find the latest version of a file by file name, version number and extension in a folder)

 

Thanks in advance to whoever remembers the location or can think of better search terms than I've been trying for the last 45mins.

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 1 of 18
(4,522 Views)
Solution
Accepted by topic author James_W

I assumes the Xs are integers and you want numeric, not alphabetic sorting. I also assume that within one run, the number of x's is constant.

 

Assuming numeric sorting, I would autoindex on the names on a FOR loop, for each use "spreadsheet string to array" with "." as delimiter and a 1D U32 array as type, Use array to cluster (Do you have an upper limit on the number of x's? Make the cluster size reasonable large), creating an array of such cluster at the autoindexing output tunnel. Sort that array and reverse the operation. To preserve the exact original formatting, add the original index as last element and, after sorting, use it to index into the original array.

Message 2 of 18
(4,513 Views)

 


@altenbach wrote:

I assumes the Xs are integers and you want numeric, not alphabetic sorting. I also assume that within one run, the number of x's is constant.

 

Assuming numeric sorting, I would autoindex on the names on a FOR loop, for each use "spreadsheet string to array" with "." as delimiter and a 1D U32 array as type, Use array to cluster (Do you have an upper limit on the number of x's? Make the cluster size reasonable large), creating an array of such cluster at the autoindexing output tunnel. Sort that array and reverse the operation. To preserve the exact original formatting, add the original index as last element and, after sorting, use it to index into the original array.


Hi Christian,

 

I would assume that they are all int too, but as I've picked the code up from a developer who's dropped it and haven't fully interfaced with the client yet, I think I might have to prepared for the possibility of an alphanumeric numbering scheme given the particular customer.

I know there was a thread that dealt with this, especially the difference between e.g. 1.0.1 and 1.0.1.1 (if we were going the numeric route) and had a final VI in it that handled the problem very nicely I just can't find the dratted thing.

 

I'll have a look into your solution now. For once it doesn't involve complex maths!Smiley Wink

 

******Edit: Sorry, forgot my manners and to say thank you. - So thank you.

Also just noticed the time, so will run now for Bible study group and hit this again first thing in the morning. ('x' max is 4 I think).****************

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 3 of 18
(4,484 Views)

For alpha sorting, use a 1D array of strings as type.

 

For different sort orders, reverse the array or not, and pad the array left or right to the cluster size. The possibilities are endless.

0 Kudos
Message 4 of 18
(4,476 Views)

For natural sort of a 1D string array (e.g. T2 comes before T10), look at the MGI library.

0 Kudos
Message 5 of 18
(4,447 Views)

If the string is really all numeric positive integers separated by periods, then you can easily create an array of the numbers using Scan from String in a While Loop.  For example, the following code produces an integer array of 12, 34, 56, and 78.Dotted Numerics.png

 

Bob Schor

0 Kudos
Message 6 of 18
(4,418 Views)

So here is my VI explaining the theory of what I am hoping to achieve before I start - As it looks like that thread is not going to resurface but I'm getting lots of great help from some of the real forum greats!Version Sort - the idea better explained.png

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 7 of 18
(4,365 Views)

As usual, Christian has come up with the goods again!

 

Version Sort.png

 

Implementing his code definition results in this VI which does exactly what I want (and highlights a flaw in my posted debug VI code Smiley Embarassed)

I'm still sure this can be optimised futher. The inclusion of the trim whitspace seems a massive overhead each run of the FOR loop - but then given the number of times this will run I shouldn't be worrying too much.

 

Thanks to all

James

 

*Edit seem to be having an issue posting the vi snippet*

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
Message 8 of 18
(4,359 Views)

Add [i] to the cluster in the first loop as an additional and last cluster element, then use it to index into the original array in the second loop. All you need in the second loop is "index array".

0 Kudos
Message 9 of 18
(4,251 Views)

@altenbach wrote:

Add [i] to the cluster in the first loop as an additional and last cluster element, then use it to index into the original array in the second loop. All you need in the second loop is "index array".


Smiley Frustrated Have I missed something? It's already sorted by the sort array function acting on the cluster. I don't want to unsort it and put it back to an original state. I thought the code was working beautifully.

What bug have I missed that's going to come back and bite me please Christian? I can't for the life of me see how [i] helps here.

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 10 of 18
(4,224 Views)