Skip to main content
Solved

How do I set a parameter value to contain a list of files when running workspace using runner.runWithParameters

  • October 17, 2017
  • 2 replies
  • 40 views

I am wanting to translate a list of files in a directory from one raster format to another by calling an FME workspace using the Python fmeobjects API.

import os
import sys
sys.path.append(r'C:\Program Files\FME\fmeobjects\python27')
import fmeobjects

workbench = r'D:\ESRIGrid2GeoTiff.fmw'
directory = r'D:\Test\A Folder'

raster_files = [os.path.join(directory, raster) for raster in os.listdir(directory)
                if raster.endswith('.asc')]

parameters = {'SourceDataset': '\"' + '\" \"'.join(raster_files) + '\"',
              'DestinationFolder': directory,
              'InputCoordinateSystem': 'MGA94-54'}

fme_runner = fmeobjects.FMEWorkspaceRunner()
fme_runner.runWithParameters(workbench, parameters)

From the log file its seems the issue is that the FME reader splits the paths where there is a space in a folder/file name, even though each path should be enclosed in double quotation marks. I can run the workbench successfully from Python if I input a single file and through FME directly without any issues.

I am wanting to keep the script as flexible as possible so I'd prefer to avoid having users always ensure their directory paths do not contain any spaces.

Best answer by takashi

Hi @bparker, probably you will have to create the paths string like this.

"""""path1"" ""path2"" ""path3"""""

That is, the value of SourceDataset should be:

'"""""' + '"" ""'.join(raster_files) + '"""""'
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Celebrity
  • 7843 replies
  • Best Answer
  • October 18, 2017

Hi @bparker, probably you will have to create the paths string like this.

"""""path1"" ""path2"" ""path3"""""

That is, the value of SourceDataset should be:

'"""""' + '"" ""'.join(raster_files) + '"""""'

  • Author
  • 1 reply
  • October 18, 2017

Hi @bparker, probably you will have to create the paths string like this.

"""""path1"" ""path2"" ""path3"""""

That is, the value of SourceDataset should be:

'"""""' + '"" ""'.join(raster_files) + '"""""'
Hi @takashi, thanks for the response, was still having the same issue with your suggested code but played around with the number of quotation marks and managed to get it working using:

 

'""""' + '""" """'.join(raster_files) + '""""'