キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

File Explorer Sort

解決済み
解決策を見る

I would like to sort files and folders EXACTLY the way File Explorer does on Windows 10.

Gone through a number of example programs from the forum but they do not work exactly.

 

Apparently File Explorer calls a function called StrCmpLogicalW.

Is there a way I could call this function from LabVIEW?

 

Appreciate any suggestions on how this can be done with LabVIEW.

0 件の賞賛
メッセージ1/16
5,470件の閲覧回数

There is of course, with the Call Library Node. But as the W at the end of the name indicates, does this function use Unicode strings while LabVIEW strings are ANSI. So you would have to convert every single file name with the function MultiByteToWideChar() first. This will get somewhat complicated to to yourself but fortunately there are functions in this thread, that do this already. You probably want to download and install the ni_lib_unicode_2.0.0.4.vip file from that list.

However it would be possible to create a similar comparison function fully in LabVIEW. The magic is to recognize numbers as whole numbers and sort the strings first alphabetically and if the part up to the number is the the same compare the numbers as whole instead of alphabetically.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
メッセージ2/16
5,440件の閲覧回数

Thank you rolfk.

Following your first paragraph, do you have an example on how should I convert the ANSI to Unicode then parse this into the Call Library Node?

0 件の賞賛
メッセージ3/16
5,414件の閲覧回数

image.png

Like this.

Benoit

0 件の賞賛
メッセージ4/16
5,401件の閲覧回数

Thanks Bseguin.

Can anyone show me how to feed this converted Unicode string into the StrCmpLogicalW function in the Call Library Node?

0 件の賞賛
メッセージ5/16
5,390件の閲覧回数

It's as "simple" as this (but the used ASCI to UTF16 function is of course Windows only too, but logically correct unlike the other proposed solution which will fail for any ASCII code point above 127):

String Compare Logical.png

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
すべてをダウンロード
0 件の賞賛
メッセージ6/16
5,383件の閲覧回数

Thank you rolfk .

 

Can you please elaborate more on your statement "but the used ASCI to UTF16 function is of course Windows only too, but logically correct unlike the other proposed solution which will fail for any ASCII code point above 127"?

 

 

0 件の賞賛
メッセージ7/16
5,368件の閲覧回数

Since my VI uses a Call Library Node to call a Windows API, it won't be possible to execute it on non-Windows LabVIEW platforms.

 

The function as proposed by bseguin does convert the ASCII codes into pseudo UTF16LE by converting all the ASCII codes 0x00 ..0xFF to 16 bit code points 0x0000 ... 0x00FF. That is only correct for the 7-bit ASCII codes 0x00 ... 0x7E. Above 0x007F the mapping between ASCII and Unicode is not the same anymore. Windows Latin-1 (codepage 1252) uses with some exceptions the same extended characters as ISO IEC8859-1 but is not the same. But if your configured local is not using Latin-1 then this mapping gets for those extended ASCII codes completely wrong.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 件の賞賛
メッセージ8/16
5,353件の閲覧回数

Rolfk, this is excellent support. Thank you.

 

Your code works intermittently at times.

When I set String 1 to 1.1 and String 2 to 1, I will get a return value of 1 (this is correct).

But then I set String 2 to 1.1 (equal to String 1), I get a return value of -1 (it should be 0).

After this when I set String 2 back to 1 (same as the first step), the return value will now change to -1 (it should be 1).

 

Do you know why this is happening?

 

Capture.JPG

 

 

0 件の賞賛
メッセージ9/16
5,338件の閲覧回数

Try with this subVI instead.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
メッセージ10/16
5,333件の閲覧回数