C#达成对点名文件夹普通话件按修改时间排序

来源:http://www.sh-fengwen.com 作者:鲜果干果 人气:109 发布时间:2019-09-03
摘要:文件夹拷贝,保留文件修改时间, 按修改时间最新排序,拷贝修改时间 import sys, os, time, shutil from stat import ST_ATIME, ST_CTIME, ST_MTIME from win32file import CopyFiledef test(self): remoteDir = "\\orc-fs\Bu

文件夹拷贝,保留文件修改时间, 按修改时间最新排序,拷贝修改时间

import sys, os, time, shutil 
from stat import ST_ATIME, ST_CTIME, ST_MTIME 
from win32file import CopyFile

def test(self): 
    remoteDir = "\\orc-fs\Builds\FP\builds01\flair\Main" 
    localDir = "d:\Main" 
    i = 0 
    for name in os.listdir(remoteDir): 
        print name 
        if i == 3: 
            break 
        shutil.copytree(os.path.join(remoteDir, name), os.path.join(localDir, name), True) 
        try: 
            stat1 = os.stat(os.path.join(remoteDir, name)) 
            print stat1 
            print time.ctime(stat1[ST_CTIME]), time.ctime(stat1[ST_MTIME]) 
        except os.error: 
            sys.stderr.write("Error") 
            sys.exit(1) 
        try: 
            os.utime(os.path.join(localDir, name), (stat1[ST_CTIME], stat1[ST_MTIME])) 
            stat2 = os.stat(os.path.join(localDir, name)) 
            os.path.getctime(os.path.join(localDir, name)) 
            print time.ctime(stat2[ST_CTIME]), time.ctime(stat2[ST_MTIME]) 
        except os.error: 
            sys.stderr.write("Error") 
            sys.exit(2) 
        if stat1[ST_CTIME] == stat2[ST_CTIME] and stat1[ST_MTIME] == stat2[ST_MTIME]: 
            print "Good" 
        i += 1 
def compare(self): 
    remoteDir = "\\orc-fs\Builds\FP\builds01\flair\Main" 
    localDir = "d:\Main" 
    files = [(os.path.getmtime(os.path.join(remoteDir, x)) , os.path.join(remoteDir, x)) for x in os.listdir(remoteDir)] 
    files.sort() 
    files.reverse() 
    for item in files: 
        print item

if __name__ == "__main__": 
    # test(1) 
    compare(1)

  

按修改时间最新排序,拷贝修改时间 import sys, os, time, shutil from stat import ST_ATIME, ST_CTIME, ST_MTIME from win32...

string path = "~/Document/Introduction/团队管理制度/";
            DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(path));
            FileInfo[] Files = dirinfo.GetFiles();
            Array.Sort<FileInfo>(Files, new FIleLastTimeComparer());

//在页面上显示最近更新的两个文件的下载链接
            for (int i = 0; i < 2; i++)
            {
                Literal literal = new Literal();
                literal.Text = "</br>";
                Panel1.Controls.Add(literal);//实现换行显示
                HyperLink hypelink = new HyperLink();
                hypelink.NavigateUrl = path + Files[i].Name;
                hypelink.Text = Files[i].Name;
                Panel1.Controls.Add(hypelink);

           }

 

public class FIleLastTimeComparer : IComparer<FileInfo>
    {
        public int Compare(FileInfo x, FileInfo y)
        {
            return y.LastWriteTime.CompareTo(x.LastWriteTime);//递减
          //return x.LastWriteTime.CompareTo(y.LastWriteTime);//递增
        }
    }

 

 

 

using System.IO;

 

private void button1_Click(object sender, EventArgs e)

{

//DirectoryInfo[] list = new DirectoryInfo(path).GetDirectories();// path:文件夹路径

DirectoryInfo[] list = new DirectoryInfo(@"D:软件").GetDirectories();

Array.Sort<DirectoryInfo>(list, new DirectoryLastTimeComparer());

 

textBox1.Text = list[list.Length - 1].FullName;//文件夹的全路径以及名字

textBox1.Text = list[list.Length - 1].Name; //文件夹的名字

}

 

private void button2_Click(object sender, EventArgs e)

{

FileInfo[] list = new DirectoryInfo(@"D:软件").GetFiles();

Array.Sort<FileInfo>(list, new FIleLastTimeComparer());

 

textBox1.Text = list[list.Length - 1].FullName;//文件的全路径以及名字

textBox1.Text = list[list.Length - 1].Name; //文件的名字

 

}

 

}

 

//文件夹中按时间排序最新的文件读取

public class DirectoryLastTimeComparer : IComparer<DirectoryInfo>

本文由美高梅游戏平台网站发布于鲜果干果,转载请注明出处:C#达成对点名文件夹普通话件按修改时间排序

关键词:

上一篇:python 之 re模块(正则表达式),pythonre

下一篇:没有了

最火资讯