Sunday, 24 April 2016

How to read files one by one with FME


In one folder I can have one or more xml files. I would like (need) to use them one by one as input dataset (reader). Actually each xml file will be used within according fme workbench regardless some values within xml file. This question is linked with my old question Variable XML dataset as reader in FME wher I got answer for one file in folder.


If I have two xml files, for instance, fme read them both at the "same time" and use values from both files for one fme wb.



Answer



I would second @Mapperz comment about upgrading - FME 2012 SP2 contains some significant improvements. If you have a current active maintenance contract then you can download the latest version direct from Safe Software.



As is always the case there are several different ways you can achieve the right result using FME. Here are two approaches you could consider:


Approach 1: MS-DOS Batch Script


When you run a workspace from within FME Workbench what you are actually doing is executing the command-line fme executable. Armed with this knowledge it is straight forward to execute a workspace from the command-line, in fact FME Workbench makes it even easier for you as the top of the log in the log viewer panel will display the command-line to use if you want to execute the workspace from a DOS prompt.


Using that information you can create a batch file to scan a directory of files and then send them one-by-one to FME for processing. For example:


SET FME="C:\Program Files\FME\fme.exe"
SET SOURCE_DATA_DIR="D:\Temp"
SET FME_WORKBENCH="YourWorkspace.fmw"
REM Set any other options here

FOR %%A IN (%SOURCE_DATA_DIR%\*.xml) DO (%FME% %FME_WORKBENCH% --SOURCE_FILE %%A)


Obviously you will need to adpat this to your needs but use the output from running your workspace in FME Workbench as a guide.


Approach 2: Controller Workspace


An alternative approach is to use a controller workspace to execute another workspace repeatedly based on some input. In this case the input will be the path to an XML file. This is straight forward to setup, all you need is a Files and Directories reader and a WorkspaceRunner transformer. An example of how this would look in FME Workbench below:


Example of a controller workspace


An extremely useful resource for all things FME is the FMEpedia site. Lots of examples and help doing all maaner of things with FME.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...