DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);
string[] filesArray = Directory.GetFiles(directoryPath, "*.*", SearchOption.TopDirectoryOnly);
Array.Sort(filesArray, new FileNameSort());
using System.Collections;
using System.Runtime.InteropServices;
public class FileNameSort : IComparer
{
[System.Runtime.InteropServices.DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
private static extern int StrCmpLogicalW(string param1, string param2);
public int Compare(object name1, object name2)
{
if (null == name1 && null == name2)
{
return 0;
}
if (null == name1)
{
return -1;
}
if (null == name2)
{
return 1;
}
return StrCmpLogicalW(name1.ToString(), name2.ToString());
}
}