0

Possible Duplicates:
Sort on a string that may contain a number
How would I sort a list of files by name to match how Windows Explorer displays them?

Greetings everyone!!!

I am facing a problem when getting files with the method Directory.GetFiles. I have files in the following sequence in my directory.

Slide1.png, Slide2.png,Slide3.png,Slide4.png and so on.

When i get the files it returns in the format Slide1.png, Slide10.png, Slide11.png,Slide12.png, Slide2.png,Slide21.png and so on...

It is sorting with the file name and combining the same values. i am trying Array.sort() but its not sorting as i want. i want the following sequence.

Slide1.png, Slide2.png,Slide3.png,Slide4.png and so on.

I am using VB.NET Framework version 4.0.

Thank you

Community
  • 1
  • 1
Zee Shan
  • 27
  • 5
  • Which version of the .Net Framework are you using? Please tag your question to indicate that you are using .Net Framework + the language you're using. – Will A May 20 '11 at 06:21
  • What is the sort order it is using, and can you post your code? – soandos May 20 '11 at 06:22

2 Answers2

0

You have to pad the numbers with zeroes, like so:

Slide01.png
Slide02.png
...
Slide10.png
...

I've had many problems with this myself, so if you have many of them to do (I had 600 images), try a batch renamer, like Metamorphose.

Blender
  • 289,723
  • 53
  • 439
  • 496
0

The problem is for us that in terms of strings, 1,10,2 is the correct order. While in numbers obviously its not.

Heres an article I found a bit back, which covers this: http://www.codeproject.com/KB/recipes/csnsort.aspx

BugFinder
  • 17,474
  • 4
  • 36
  • 51