zoukankan      html  css  js  c++  java
  • 过滤文件代码 python

    import os
    import cv2
    import shutil
    
    # store all file in directory
    global totalFileList
    totalFileList  = []
    
    
    def eachFile(filepath):
        pathDir = os.listdir(filepath)
        totalFileList.extend([os.path.join(filepath,filename) for filename in  os.listdir(filepath)])
        print 
        for s in pathDir:
            newDir=os.path.join(filepath,s)     
            if os.path.isfile(newDir) :         
                if os.path.splitext(newDir)[1]==".txt":   
                    readFile(newDir)                     
                    pass
            else:
                eachFile(newDir)                 
    
    def slectFile(filelist, keyword='jpg', check=True):
        validFileList = []
        validCount = 0
        for fnum, fname in enumerate(filelist):
            fname = fname.strip()
            if not os.path.exists(fname):
                continue 
            if keyword not in os.path.splitext(fname)[-1]:
                continue
            if check:
                img = cv2.imread(fname)
                if None == img:
                    continue
                height, width, channel = img.shape
                if (height <= 0) or (width <= 0) or (not channel  == 3):
                    continue 
            validCount += 1
            validFileList.append(fname)
        return validFileList
    
    def copyFile(filelist, tgdir):
        if len(filelist) == 0:
            return None
        if not os.path.exists(tgdir):
            os.makedirs(tgdir)
        for file_num, file_name in enumerate(filelist):
            filePath,fileName = os.path.split(file_name)
            newFileName = os.path.join(tgdir, 'skeleton_neg_%08d.jpg'%file_num)
            shutil.copyfile(file_name, newFileName) 
        
    if __name__ == "__main__":
       eachFile('./')
       validFileList = slectFile(totalFileList)
       copyFile(validFileList, tgdir='./valid')
       print 'Done'
  • 相关阅读:
    HTB-靶机-Lazy
    HTB-靶机-Brainfuck
    HTB-靶机-October
    java编程思想-java注解
    HMAC的JAVA实现和应用
    HMACSHA1算法的JAVA实现
    常见软件安全漏洞样例代码
    [移动应用安全]移动应用安全培训PPT
    [标准性文档]WEB应用安全验证标准
    [安全测试报告]针对某厂商的一次渗透性测试
  • 原文地址:https://www.cnblogs.com/ruichenduo/p/7929683.html
Copyright © 2011-2022 走看看