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)

  • 相关阅读:
    【问题 & 解决】git 克隆项目时超时
    【荐】开源Winform控件库:花木兰控件库
    virtualenv Python 项目环境搭建必备
    英文电影评论情感分析
    中华古诗词知识图谱构建之数据获取
    基于Word2vec的诗词多情感分析
    中华古诗词知识图谱之网页设计及实现(完结)
    1211诗词时空背景
    1217诗词鉴赏
    中华古诗词知识图谱之实体关系构建&导入neo4j数据库
  • 原文地址:https://www.cnblogs.com/shenfei2031/p/2132735.html
Copyright © 2011-2022 走看看