LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

list files from a folder

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

0 Kudos
Message 1 of 18
(713 Views)

So, you need a special sorted list of files? not the string sorting?

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 18
(709 Views)

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:

  • What is the sort order in FileExplorer?
  • What should happen when you change the sort order in FileExplorer?
  • Why don't you apply the same sorting order to the array of filenames that you got from the ListFolder function?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 18
(708 Views)

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.

0 Kudos
Message 4 of 18
(703 Views)

The concept is called Alpha-Logical sorting.

 

https://forums.ni.com/t5/Example-Code/AlphaLogical-Bubble-Sorting-Algorithm-in-LabVIEW/ta-p/3492488

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 5 of 18
(679 Views)

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.

Message 6 of 18
(666 Views)

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

0 Kudos
Message 7 of 18
(624 Views)

@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.

Rolf Kalbermatter
My Blog
Message 8 of 18
(592 Views)

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:

 

altenbach_0-1727279411462.png

 

 

 

 

0 Kudos
Message 9 of 18
(550 Views)

@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.

0 Kudos
Message 10 of 18
(498 Views)