Skip to main content
Question

Parsing Filename(multiple) parameters

  • September 22, 2017
  • 2 replies
  • 18 views

jdh
Contributor
Forum|alt.badge.img+40

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""
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

daveatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • September 22, 2017

Hi @jdh,

You could try:

source = FME_MacroValues['Param1']
filelist = shlex.split(shlex.split(source)[0])

takashi
Celebrity
  • September 22, 2017

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