zoukankan      html  css  js  c++  java
  • 文件夹拷贝,保留文件修改时间, 按修改时间最新排序

    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)

  • 相关阅读:
    VBScript学习笔记
    C#调用C++库知识点
    .Net面试经验,从北京到杭州
    杭州.Net 相关大公司,希望对大家有帮助
    一起学习《C#高级编程》3--运算符重载
    一起学习《C#高级编程》2--比较对象的相等性
    一起学习《C#高级编程》1--类型的安全性
    博客园的第一天
    基于SpringCloud+Kubernetes 微服务的容器化持续交付实战
    第一节:Docker学习 — 安装
  • 原文地址:https://www.cnblogs.com/shenfei2031/p/2132735.html
Copyright © 2011-2022 走看看