Skip to main content
Open

Multiplereader

Related products:FME Form
  • June 7, 2023
  • 1 reply
  • 20 views
danilo_fme
wilsonlee
ronnie.utter
  • danilo_fme
    danilo_fme
  • wilsonlee
    wilsonlee
  • ronnie.utter
    ronnie.utter

ronnie.utter
Contributor

All readers today is for only one extension in a time. Sometime you have to upload multiple files in a flow. It would be nice to be able to add a zip with multiple files. And then the path for each files to use in a reader at your choice.


This pythonscript read all files in a zip and returns the path. You need a attribute exposer to get the attributes.


import zipfile

import os

import fmeobjects


class FeatureProcessor(object):

  def __init__(self):

    pass


  def input(self, feature):

    zip_path = r'yourzipfile.zip'

    extract_to = os.path.dirname(zip_path)


    with zipfile.ZipFile(zip_path, 'r') as zip_ref:

      zip_ref.extractall(extract_to)

      for file in zip_ref.namelist():

        f = fmeobjects.FMEFeature()

        f.setAttribute('file_name', file)

        f.setAttribute('file_path', os.path.join(extract_to, file))

        self.pyoutput(f)


  def close(self):

    pass


1 reply

JennaKAtSafe
Safer
Forum|alt.badge.img+7

FME treats zip files as folders, Have you tried using the Generic format in the FeatureReader with the zip file as the dataset? Would this fully address what you’re looking for here?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings