• python 批量处理文件


    def GetFileList(dir, fileList,notdeal=[]):
        newDir = dir
        if os.path.isfile(dir):
            fileList.append(dir)
        elif os.path.isdir(dir):
            for s in os.listdir(dir):
                #如果需要忽略某些文件夹,使用以下代码
                if s in notdeal:
                    continue
                newDir = os.path.join(dir, s)
                GetFileList(newDir, fileList,notdeal)
        return fileList
    
    def pushFileinFold(filename,foldname,createpath=False):
        retname=''
        names=filename.split('/')
    
        if foldname[0]=='/':
            retname=foldname
        else:
            for i in range(len(names)-1):
                retname =retname+names[i]+'/'
            retname+=foldname
        if createpath==True:
            if os.path.exists(retname)==False:
                os.makedirs(retname)
                # print(retname+'/'+ names[len(names) - 1])
        return retname +'/'+ names[len(names) - 1]
    
    filepath
    = "/home/b/a" lists = GetFileList(filepath, [],['deal','python']) for i in range(len(lists)):   globals()['data'+str(i)]=pd.read_csv(lists[i],header=None)
      #对数据进行处理
      globals()['data'+str(i)].to_excel(pushFileinFold(lists[i],'deal',True))

    读取/home/b/a文件夹子下的所有文件,里面的deal,python文件夹不处理

    数据处理后保存到 文件所在位置的deal文件夹下,若是文件夹不存在则创建

  • 相关阅读:
    SQLDirect 6.5 Source (Delphi 5-10.1 Berlin)
    中国自主X86处理器工艺跃进:国产28nm升级16nm(上海兆芯)
    底层库
    An Overview of Complex Event Processing2
    linux动态库编译和使用
    gulp
    Web前端性能优化
    ECLIPSE JSP TOMCAT 环境搭建
    项目架构mvc+webapi
    HTTP/1.1
  • 原文地址:https://www.cnblogs.com/skycandy/p/9303864.html
Copyright © 2020-2023  润新知