-
HELP!! Sort File List Box
[Originally posted by Happy Cat]
I set the path of the FileListBox to get all the text files within the directory.
The problem is : The file list are initially sorted by file name rather than Date Modified.
The file name listed as below :
File1
File10
File11
File2
File3
Rather than
File1
File2
File3
..
File10
Please Help
Thank you˙ ^_^
-
Re:HELP!! Sort File List Box
[Originally posted by Bj”rn Gustafsson]
Well, the problem is that VB (as all other ms stuff) uses "ascii comparision" when comparing filenames.
And 2 is larger than 1, and "." is smaller than 0. So what happens is:
(lets compare File2 and File10)
"F" = "F"
"i" = "i"
"l" = "l"
"e" = "e"
"2" > "1" --> Here, we have found that File10 has a "lower" filename than File2, and should therefore appear before it.
therefore, File10/11/12...19 would appear before file2.
The solution is of course to have File01, File02... File09, since 0 <1|2|3|4...9, or even 001,002...099 if you have more than a 100 files.
˙ /Bj”rn
-
Re:Re:HELP!! Sort File List Box
[Originally posted by Happy Cat]
But, the problem is I wouldn't know how many files will it have because the file will be auto-generated from other sources from time to time.
Is it possible if we sort it by Date Created or do you have better suggestion for the file naming ?
Thank you!!!
-
Re:Re:Re:HELP!! Sort File List Box
[Originally posted by Bj”rn Gustafsson]
Well, I'd suggest padding the file ID with '0', as mentioned earlier.
I haven't used the file-listbox since VB3, so I don't know if there is a possibility to sort on date or any other parameter.
Personally, I always use '0' padding, in order to get the files in the correct order in Explorer too, and the number is up to you.
If you're going with the normal 8.3 standard, you might want to remove the "File*" name, but that all depends on how many files you expect to generate....
Or you could always skip the "file1" totally, and use the date/time as filename instead :)
"010501_1430.txt" or whatever...
Quick code-byte:
FileName = "file" & string(4-len(FileID), "0") & ".txt"
This would give you filenames as "file0001.txt" and so on.
˙ /Bj”rn
-
Re:Re:Re:Re:HELP!! Sort File List Box
[Originally posted by Happy Cat]
Thank you, Bj”rn,
˙ you have given me a very good solution. I'll use the filename with date time so that it'll always in sequence.
˙ Thanks a lot!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks