09-23-2024 01:46 PM
My folder has files named cmp.1.csv, cmp.2.csv,...,cmp.10.csv, csv.11.csv etc. When I use the list folder function they come out as cmp.1.csv, cmp.10.csv, cmp.11.csv etc instead of 1, 2, 3, ... Is there a way to make them come out as Windows File Explorer lists them? Thank you.
Girish
09-23-2024 01:55 PM
So, you need a special sorted list of files? not the string sorting?
09-23-2024 01:55 PM
Hi girish,
@girish53 wrote:
My folder has files named cmp.1.csv, cmp.2.csv,...,cmp.10.csv, csv.11.csv etc. When I use the list folder function they come out as cmp.1.csv, cmp.10.csv, cmp.11.csv etc instead of 1, 2, 3, ... Is there a way to make them come out as Windows File Explorer lists them?
Short answer: yes!
Long(er) reply:
09-23-2024 02:01 PM
FileExplorer lists them as cmp.1.csv, cmp.2.csv, cmp.3.csv,...,cmp.9.csv, cmp.10.csv, cmp.11.csv,.. etc. I want to treat the characters between two dots as numbers as order them as numbers.
09-23-2024 02:17 PM
The concept is called Alpha-Logical sorting.
https://forums.ni.com/t5/Example-Code/AlphaLogical-Bubble-Sorting-Algorithm-in-LabVIEW/ta-p/3492488
09-23-2024 02:26 PM
Does your software generate these file names and create them?
If so, also consider just saving them as cmp.00001.csv, cmp.00002.csv, and so on.
09-23-2024 03:53 PM
How interesting! There is a hidden key buried in the Windows Registry that can turn on or turn off Numerical sorting in file names!
I have no idea when this was introduced. I can certainly say that I've gone to some trouble to make sure that my file names sort "literally" (i.e. treating all the characters in the name as characters, not as possible numbers), typically by making them at least 3 digit long, starting with 001. [This might blow up if I have 1000 data files with the same naming scheme, of course ...].
This reminds me of a colleague who embedded Time Stamp information into the filename. What a mess! Dec 2025 sorts before Jan 2008!
Of course, it is easy enough to get a list of the file names (in any old order) into an array and write a little LabVIEW routine that sorts the array according to whatever "sort" rules you want to impose. Give some thought about how you might write such a routine.
Bob Schor
09-24-2024 01:01 AM - edited 09-24-2024 01:09 AM
@Bob_Schor wrote:
How interesting! There is a hidden key buried in the Windows Registry that can turn on or turn off Numerical sorting in file names!
I have no idea when this was introduced. I can certainly say that I've gone to some trouble to make sure that my file names sort "literally" (i.e. treating all the characters in the name as characters, not as possible numbers), typically by making them at least 3 digit long, starting with 001. [This might blow up if I have 1000 data files with the same naming scheme, of course ...].
This reminds me of a colleague who embedded Time Stamp information into the filename. What a mess! Dec 2025 sorts before Jan 2008!
Of course, it is easy enough to get a list of the file names (in any old order) into an array and write a little LabVIEW routine that sorts the array according to whatever "sort" rules you want to impose. Give some thought about how you might write such a routine.
If you add dates and times to the filenames the only sane way is to add them as YYYYMMDDHHMMSS, with whatever extra separation characters you want to add in between. And it should be military time too, aka 24 hours.
Anything else is a mess whenever someone has to manually access the files later.
As to the problem from the OP, if you want a specific sort order you have to sort your elements accordingly. LabVIEW as programming language gives you all the tools to do your own sort algorithms. Sorting is not a trivial thing to do but their are also umpteen different possibilities and the List Folder function can’t offer them all.
09-25-2024 10:50 AM
As you can see, the files will be sorted alphabetically, not numerically. As has been mentioned, it is typically advantageous to pad numbers in filenames with sufficient zeroes so alphabetic sorting = numeric sorting. (alphabetically, 100 < 99, while 100 >099).
If you don't have control over the filenames, you can just sort the array of names according to your needs, e.g. as follows:
09-26-2024 04:36 AM
@Bob_Schor wrote:
How interesting! There is a hidden key buried in the Windows Registry that can turn on or turn off Numerical sorting in file names!
I have no idea when this was introduced. I can certainly say that I've gone to some trouble to make sure that my file names sort "literally" (i.e. treating all the characters in the name as characters, not as possible numbers), typically by making them at least 3 digit long, starting with 001. [This might blow up if I have 1000 data files with the same naming scheme, of course ...].
This reminds me of a colleague who embedded Time Stamp information into the filename. What a mess! Dec 2025 sorts before Jan 2008!
Of course, it is easy enough to get a list of the file names (in any old order) into an array and write a little LabVIEW routine that sorts the array according to whatever "sort" rules you want to impose. Give some thought about how you might write such a routine.
Bob Schor
For sortable dates with good readability, I use this format 2025-09nov-01.