zoukankan      html  css  js  c++  java
  • python每日一题:文件的备份与查找

    题目:查找下列文件,列出所有的文件名,并列出最近一次修改的文件,和最早建立的文件。 

     

      先列代码,仅仅作为练习。

    import os,time
    def commax(value):## 比较时间函数,返回最大数值的序号
        if value[0] > value[1]:
            t = 0
        else:
            t = 1
        if value[t] <value[2]:
            t = 2
        return t
    
    def commin(value):## 比较时间函数,返回数值最小数值序号
        if value[0] <value[1]:
            t = 0
        else:
            t = 1
        if value[t] >value[2]:
            t = 2
        return t
    
    source="c:\aa"
    files=os.listdir(source)#列出aa目录下所有的文件
    file0=os.stat(source+os.sep+files[0])#列出第一个文件的所有属性,一共10个,包括st_mtime和st_ctime
    file1=os.stat(source+os.sep+files[1])
    file2=os.stat(source+os.sep+files[2])
    file=[file0,file1,file2]
    a=[file[0][8],file[1][8],file[2][8]]#找出st_mtime的数值
    b=[file[0][9],file[1][9],file[2][9]]#找出st_ctime的数值
    print( "The searching result is:")
    print( "The file sum:",len(files))
    for num in  range(len(files)):
        print(num,":",files[num],",","the modifed time is:",file[num][8],"the created time is:",file[num][9],)
    print("After inqurying, the recent modifed file is:",files[commax(a)])
    print("the latest created file is:",files[commin(b)],)

     编译结果如下:

    The searching result is:
    The file sum: 3
    0 : dt1000 , the modifed time is: 1543491750 the created time is: 1543489504
    1 : dt1000 - 副本 , the modifed time is: 1543495031 the created time is: 1543495031
    2 : dt1000 - 副本 (2) , the modifed time is: 1543495108 the created time is: 1543495093
    After inqurying, the recent modifed file is: dt1000 - 副本 (2)
    the latest created file is: dt1000

    由于代码比较简单,不做详细描述

  • 相关阅读:
    网络设备snmp配置syslog方法。
    Oracle19c安装手册Windows及mysql-oracle转换
    Oracle11g--hxss安装
    VMWare ESXI 6.5 的部署及简单使用的说明
    windos下redis的启动与安装
    二、fidder 和 python结合进行 get post 请求发送
    一、fidder工具使用
    Python学习二《数据类型介绍》
    Python学习一《基础规范》
    Charles设置为代理服务
  • 原文地址:https://www.cnblogs.com/xuehaiwuya0000/p/10030907.html
Copyright © 2011-2022 走看看