Linux安全网 - Linux操作系统_Linux 命令_Linux教程_Linux黑客

会员投稿 投稿指南 本期推荐:
搜索:
您的位置: Linux安全网 > Linux编程 > » 正文

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

来源: 未知 分享至:

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)


Tags:
分享至:
最新图文资讯
1 2 3 4 5 6
验证码:点击我更换图片 理智评论文明上网,拒绝恶意谩骂 用户名:
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 发展历史