Windows资源管理器自定义文件排序名称顺序 [英] Windows explorer custom file sort name order

查看:792
本文介绍了Windows资源管理器自定义文件排序名称顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如果我想创建一个程序来调整按名称排序时窗口列出资源管理器中文件的顺序,我会从哪里开始?我希望文件按文件名末尾的唯一编号排序,而不是使用通用windows
排序算法,该算法从文件名的开头按字母/数字顺序排序名称。这可能吗?


例子-0001.pdf

ANEXAMPLE-0002.pdf

ANOTHEREXAMPLE-0003.pdf



谢谢



解决方案


如果你有一个包含字符串的列表,你可以这样做:

 static void Main(string [] args)
{
var list = new List< string>
{
" ANEXAMPLE-0002.pdf",
" EXAMPLE-0001.pdf",
" ANOTHEREXAMPLE-0003.pdf"
};
list = list.OrderBy(x => GetInt(x))。ToList();
}
public static int GetInt(string str)
{
var match = Regex.Match(str,@"(?< = \ - )(。* ?)(= \)");
if(!Int32.TryParse(match?.Value,out int i))
throw new Exception();
返回i;
}


问候,Chris




Hi,

Where would I start if I wanted to create a program to adjust the order in which windows lists files in explorer when ordered by Name? I would like the files to be sorted by a unique number at the end of the file name rather than using the generic windows sorting algorithm which orders the names in alphabetical/numerical order from the start of the file name. Is this possible?

EXAMPLE-0001.pdf
ANEXAMPLE-0002.pdf
ANOTHEREXAMPLE-0003.pdf

Thanks

解决方案

Hi,

if you have a list with the strings, you can do something like this:

        static void Main(string[] args)
        {
            var list = new List<string>
            {
                "ANEXAMPLE-0002.pdf",
                "EXAMPLE-0001.pdf",
                "ANOTHEREXAMPLE-0003.pdf"
            };
            list = list.OrderBy(x => GetInt(x)).ToList();
        }
        public static int GetInt(string str)
        {
            var match = Regex.Match(str, @"(?<=\-)(.*?)(?=\.)");
            if (!Int32.TryParse(match?.Value, out int i))
                throw new Exception();
            return i;
        }

Greetings, Chris



这篇关于Windows资源管理器自定义文件排序名称顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆