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

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)

转载于:https://www.cnblogs.com/shenfei2031/archive/2011/08/09/2132735.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值