using System;
using System.Collections.Generic;

namespace Microsoft.Xna.User.GraphicsDeviceUserControl
{
  public class FilesNameSort : IComparer<string>
  {
    [System.Runtime.InteropServices.DllImport("Shlwapi.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
    public static extern int StrCmpLogicalW(string str1, string str2);
    public int Compare(string str1, string str2)
    {
      return StrCmpLogicalW(str1, str2);
    }
  }
  public partial class MyForm : Form
  {
    public MyForm()
    {
      InitializeComponent();
    }

    private void Button_Click(object sender, EventArgs e)
    {

      FolderBrowserDialog dialog = new FolderBrowserDialog();

      if (dialog.ShowDialog() == DialogResult.OK)
      {
        string strPath = dialog.SelectedPath;

        DirectoryInfo theFolder = new DirectoryInfo(strPath);

        FileInfo[] theFiles = theFolder.GetFiles("*.xnb");
        theFiles = theFiles.OrderBy(y => y.Name, new FilesNameSort()).ToArray();

        string[] files = new string[theFiles.Length];

        for (int i = 0; i < files.Count(); i++)
        {
          files[i] = Path.GetFileNameWithoutExtension(theFiles[i].FullName);
        }
      }
    }
  }
}

posted on 2020-01-02 16:41  _萧朗  阅读(423)  评论(0编辑  收藏  举报