c# 文件排序

didiaogao 2010-10-12 04:33:02
我想对一个文件夹下的所有文件按名称排序,改怎么实现
...全文
78 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
didiaogao 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wuyazhe 的回复:]
某文件夹下创建3个文本文件分别a1,a2,a3运行结果
C:\Users\wuyazhe\Desktop\新建文件夹 (2)\a1.txt
C:\Users\wuyazhe\Desktop\新建文件夹 (2)\a2.txt
C:\Users\wuyazhe\Desktop\新建文件夹 (2)\a3.txt

C# code

[STAThread]
static void Main……
[/Quote]

用创建时间排可以解决。谢谢你啊。。。
兔子-顾问 2010-10-12
  • 打赏
  • 举报
回复
某文件夹下创建3个文本文件分别a1,a2,a3运行结果
C:\Users\wuyazhe\Desktop\新建文件夹 (2)\a1.txt
C:\Users\wuyazhe\Desktop\新建文件夹 (2)\a2.txt
C:\Users\wuyazhe\Desktop\新建文件夹 (2)\a3.txt

[STAThread]
static void Main(string[] args)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.SelectedPath = Application.CommonAppDataPath;
dlg.ShowDialog();
string[] files = Directory.GetFiles(dlg.SelectedPath);
Array.Sort(files);
//files就是排序后的文件路径列表
foreach (string file in files)
{
Console.WriteLine(file);
}
Console.ReadKey();
}
兔子-顾问 2010-10-12
  • 打赏
  • 举报
回复
代码都贴了,效果对不对都能自己去试。如果结果不是你要的。你看看楼上,想法都一样的,说明问题是你没描述清楚。
自己重新描述下问题吧。
didiaogao 2010-10-12
  • 打赏
  • 举报
回复
文件夹下面的 文件名称是有规律的。。


1.JPG,2.JPG,3.JPG,4.JPG,5.JPG...........
didiaogao 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jaydawson 的回复:]
引用 2 楼 wuyazhe 的回复:

C# code
string[] files = Directory.GetFiles("路径", "*.扩展名");
Array.Sort(files);
//files就是排序后的文件路径列表


正解
[/Quote]

非正解
jaydawson 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyazhe 的回复:]

C# code
string[] files = Directory.GetFiles("路径", "*.扩展名");
Array.Sort(files);
//files就是排序后的文件路径列表
[/Quote]

正解
兔子-顾问 2010-10-12
  • 打赏
  • 举报
回复
string[] files = Directory.GetFiles("路径", "*.扩展名");
Array.Sort(files);
//files就是排序后的文件路径列表
Return门徒 2010-10-12
  • 打赏
  • 举报
回复
获取所有文件夹名称,存入list集合,使用list的sort()

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧