Skip to main content
Solved

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


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) + '"""""'
View original
Did this help you find an answer to your question?

2 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • 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
  • October 18, 2017
takashi wrote:

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) + '""""'

Reply


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