• python 查找文件,循环遍历文件夹,获取文件夹中的某个文件中的文件,判断文件是否包含在某个文件夹下


    
    import os
    
    filepath = r'C:Usersqm66AppDataLocalEncooEncoo RobotJobLogslocal管理员权限可以访问的文件1.0.0'
    filelist = []
    
    
    # 拿到所有的日志文件
    class LogFile:
        try:
            pathDir = os.listdir(filepath)
            for allDir in pathDir:
                child = os.path.join('%s%s' % (filepath, allDir))
                # print('打印文件', child)
                filelist.append(child)
                # print('所有文件', filelist)
            '''
            1.拿到最后一个(即最新的执行时间的文件)
            2.需要做字符串取值,拿到后14个字符
            3.做字符串拼接,获取到真正正确的路径,可输入文件位置直接打开的文件有效路径
            4.校验log文件是否存在
            5.校验截图文件是否存在,获取文件中的截图数量,打印输出结果
            '''
            endfile_name = filelist[-1]
            # print(type(endfile_name), endfile_name)
            # print('拿到后14个字符', endfile_name[-14:])
            new_file = endfile_name[-14:]
            rod = f'{new_file}'
            # 我是最后转换的正确路径
            correct_path = filepath + rod
            # print('我是最后转换的正确路径', correct_path)
            # 进行文件夹内容循环获取
            pathDir = os.listdir(correct_path)
            for allDir in pathDir:
                child = os.path.join('%s%s' % (filepath, allDir))
                # print('打印正确的文件', type(child), child)
                correctlogname = 'job-' + new_file + '.log'
                jietu = 'Screenshots'
                if correctlogname and jietu in child:
                    print('日志文件已存在,Screenshots文件已存在')
            # 截图路径
            jietu_road = 'Screenshots'
            correct_jietu_road = correct_path + jietu_road
            # print('我是最后转换的正确路径', correct_jietu_road)
            pathDir = os.listdir(correct_jietu_road)
            child_list = []
            for allDir in pathDir:
                child = os.path.join('%s%s' % (filepath, allDir))
                # print('打印正确的文件', type(child), child)
                child_list.append(child)
                jietu_num = len(child_list)
                # print('我最后的值是', len(child_list), child_list)
                if 'jpg' in child:
                    print(f'执行截图功能通过,总共有{jietu_num}张截图')
        except:
            print('系统资源文件不匹配,非有效文件路径,点击Robot日志,检查对应磁盘文件配置')
    
    LogFile()
    
  • 相关阅读:
    jQuery tips
    WCF4.0进阶系列—第十一章 编写代码控制配置和通信 (上)
    WCF4.0进阶系列—第九章 事务支持(上)
    WCF4.0进阶系列第二章 寄宿WCF服务
    WCF4.0进阶系列第五章 在因特网环境下保护WCF服务
    [JavaScript] onkeypress and onchange event
    [JavaScript]使用jQuery定制开发自己的UI
    WCF4.0进阶系列第四章 保护企业内部的WCF服务
    WCF4.0进阶系列第六章 维护服务协定和数据协定
    WCF4.0 进阶系列第一章 WCF简介
  • 原文地址:https://www.cnblogs.com/ludundun/p/14164372.html
Copyright © 2020-2023  润新知