首页 > 编程语言 > 详细

文件夹目录排序

时间:2020-01-02 17:54:47      阅读:124      评论:0      收藏:0      [点我收藏+]

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);
        }
      }
    }
  }
}

文件夹目录排序

原文:https://www.cnblogs.com/XiaoLang0/p/12133816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!