I have files in directory like that
0-0.jpeg
0-1.jpeg
0-5.jpeg
0-9.jpeg
0-10.jpeg
0-12.jpeg
....
when i loading files:
You filenames appear to be structured. If you just sort them, they sort as ordinary strings. You need to:
Personally, I'd create a class that represented the structure implicit in the filename. Perhaps it should wrap the FileInfo. The constructor for that class should parse the filename into its constituent parts and instantiate the properties of the class appropriately.
The class should implement IComparable/IComparable (or you could create an implementation of Comparer).
Sort your objects and they should then come out in the collating sequence you desire.
If looks like your file names are composed of 3 parts:
So your class might look something like
public class MyFileInfoWrapper : IComparable,IComparable
{
public MyFileInfoWrapper( FileInfo fi )
{
// your implementation here
throw new NotImplementedException() ;
}
public int Hi { get ; private set ; }
public int Lo { get ; private set ; }
public string Extension { get ; private set ; }
public FileInfo FileInfo { get ; private set ; }
public int CompareTo( MyFileInfoWrapper other )
{
int cc ;
if ( other == null ) cc = -1 ;
else if ( this.Hi < other.Hi ) cc = -1 ;
else if ( this.Hi > other.Hi ) cc = +1 ;
else if ( this.Lo < other.Lo ) cc = -1 ;
else if ( this.Lo > other.Lo ) cc = +1 ;
else cc = string.Compare( this.Extension , other.Extension , StringComparison.InvariantCultureIgnoreCase ) ;
return cc ;
}
public int CompareTo( object obj )
{
int cc ;
if ( obj == null ) cc = -1 ;
else if ( obj is MyFileInfoWrapper ) cc = CompareTo( (MyFileInfoWrapper) obj ) ;
else throw new ArgumentException("'obj' is not a 'MyFileInfoWrapper' type.", "obj") ;
return cc ;
}
}