Question

Parsing Filename(multiple) parameters

  • 22 September 2017
  • 2 replies
  • 0 views

Badge +22
  • Contributor
  • 1961 replies

What method do use to parse the Filename (multiple) parameter in python?

 

 

I currently use

 

source = FME_MacroValues['Param1']
if source.startswith('"'):
from shlex import split
fileList = split(source[1:-1])
else:
fileList=[source] 

 

but it feels clunky.

 

 

The assumption is that if it's a single file, it is not wrapped in quotes, but if it's multiple files it is:

 

""file1" "file2" "file3""

2 replies

Userlevel 2
Badge +17

Hi @jdh,

You could try:

source = FME_MacroValues['Param1']
filelist = shlex.split(shlex.split(source)[0])
Userlevel 2
Badge +17

The shlex.split method may not work as expected if a file path could contain a space, so I would use str.strip and str.split method simply. This works like the AttributeTrimmer and the AttributeSplitter.

source = FME_MacroValues['Param1']
filelist = source.strip('"').split('" "')

Reply