Created 04-07-2025 08:19 AM
Hi
I will like to append forward slash / conditionally in EL. But not able to acheive it.
${extracted.path:length():gt(0):ifElse(${extracted.path:append('/'):append(${filename})},${filename})}
Have tried using ${literal('/')} as well but its not getting the value.
Thanks
Created 04-08-2025 05:18 AM
The NiFi EL you are using is valid and works. So this raise the question as to where you are trying to use it?
I validated your EL using the UpdateAttribute processor.
I do have another question about your ifElse:
A more typical approach would be t simply use ${extracted.path}/${filename} in the processor that writes file out to destination. If extracted.path is empty or does not exist it returns nothing.
Please help our community grow. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.
Thank you,
Matt
Created 04-10-2025 11:53 AM
hi @MattWho
Our use case is to retain the same nested folder structure as the source.
AS you mentioned I did use "${extracted.path}/${filename}", however in case of "demo109.txt" the "extracted.path" is empty and gets created as "/${filename}" with forward slash at the begining.
To avoid this we wanted to set "/" conditionally.
Thanks
Created 04-11-2025 05:53 AM
@nifier
I am not seeing the same behavior as you have reported which make me think your extracted.path is not not really 0 bytes.
I suggest adding another dynamic property to your update Attribute processor to output the calculated length to verify.
Here is what i see after my UpdateAttribute processor (newdir is set using your shared NiFi Expression Language (NEL) statement).
So I created extracted.path with a single white space and then see what you describe, but that whitespace is a byte, so expected output:
If it turns out your problem is because you have white space in the Extracted.path attribute, you could modify your NEL statement as follows:
${extracted.path:trim():length():gt(0):ifElse(${extracted.path:append('/'):append(${filename})},${filename})}
You use the trim() NEL function to remove leading or trialing whitespace from the extracted.path before calculating length. This includes trimming of a line return.
So in below you will see desired output even though extracted.path length is not 0 because I trimmed white space or line return.
Please help our community grow. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.
Thank you,
Matt