03-02-2009 06:39 PM
Hi there,
I keep running into a problem whenever I need to list files sequentially. Instead of 0,1,2,...10,11,12...100,101,... The files get listed in the following "alphabetical" order: 0,1,10,100,101,...11,110,...,12,120,121,...,2,20,200...
I understand that a simple solution would be to list the files by timestamp, and I have done this in the past, but this solution is not available to me this time.
The timestamp on files is very sensitive: Sometimes I need to manually mess with some of the files after I create them, thus reseting the timestamp on them. Another problem comes up when I create files too quickly, they end up sharing the same timestamp again being sorted incorrectly/alphabetically. A solution to that is to create files with an artificial time delay of a second between creations. This is very time consuming and not feasible in real-time applications.
Sorry to get longwinded. I'm just wondering if there is a simple way to list files from a folder sequentially by just using their filename (which ends on a #)?
Solved! Go to Solution.
03-02-2009 06:52 PM
This issue is because Windows sorts file names alphabetically, 1 comes before 10, before 11, which are before 2, 20, 21.
You should create the file names zero filled. If you know that you will go up to 99 files, name them 01, 02, ... 09, 10, 11 , 99. If you need more than 100, go 001, 002, ... 010, . 099, 100, 101 ... 999. Then the alphbetical sorting will also be numerically sorted.
03-03-2009 02:05 AM
Hi
In windows both the date/time for creating and last mod are saved in the file. Labview has a function called "File/Directory Info" this will give you the date for last modification. This may not be the same as date created. So take a look at my solution in this post http://forums.ni.com/ni/board/message?board.id=170&message.id=384761#M384761. It may be what you want to do
03-03-2009 05:32 AM - edited 03-03-2009 05:39 AM
The first For Loop is only there to make some data for me to work with; you'd replace that with your array of file names. Replace the Decimal String To Number function I used with a Match Pattern (to get the number from your file's name) and you'll have a cluster of integer & string which will sort the way you want it to.
03-03-2009 05:44 AM
03-03-2009 06:51 AM
jcarmody,
Very nice application of Darren's nugget.
03-03-2009 10:45 AM