有关文件的创建并按照时间排序

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
    public struct FileInfos
    {
        public string fileName;
        public DateTime fileCreateTime;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        DirectoryInfo info = new DirectoryInfo(@"c:/windows");
        FileInfo[] infos = info.GetFiles();
        //Array.Sort(infos, new CompareFileInfo());
        FileInfos[] arryInfos = new FileInfos[infos.Length];
        for (int i = 0; i < infos.Length; i++)
        {
            arryInfos[i].fileName = infos[i].Name;
            arryInfos[i].fileCreateTime = infos[i].CreationTime;
        }

        //对数组根椐文件创建时间进行冒泡排序
        FileInfos FileInfoTemp;
        for (int k = 0; k < infos.Length; k++)
        {
            for (int j = k + 1; j < infos.Length; j++)
            {
                if (DateTime.Compare(arryInfos[k].fileCreateTime, arryInfos[j].fileCreateTime) < 0)
                {
                    FileInfoTemp = arryInfos[k];
                    arryInfos[k] = arryInfos[j];
                    arryInfos[j] = FileInfoTemp;
                }
            }
        }
        for (int i = 0; i < arryInfos.Length; i++)
        {
            Response.Write("<br>" + arryInfos[i].fileName.ToString() + "------>" + arryInfos[i].fileCreateTime.ToString("yyyy-MM-dd hh:mm:ss"));
        }
    }
}

你可能感兴趣的:(有关文件的创建并按照时间排序)