Support Questions

Find answers, ask questions, and share your expertise

Adding timestamp to the file name before extension

avatar
Explorer

Hi Team,

I want to rename/modify the filename of the flowfile with the timestamp added to it. Let's say the original flowfile name is file1.txt, I want to change the name of file to be file1_<timestamp>.txt. I used updateAttribute processor to do it. The expression which I gave is

 

${filename:substringBeforeLast(‘.’)}_${now():format("yyyy-MM-dd HH:mm:ss.SSS’Z’”)}.${filename:substringAfter('.')}

 

This Giving me error. I'm bad at Expression language. could anyone help me in this?
Thanks. 

1 ACCEPTED SOLUTION

avatar
Master Mentor

Hello @girish6

 

Your first EL statement would work as well once you correct the single quote marks around the Z. 

Many outside text editors end up messing up the single quotes, so the NiFi EL ends up being incorrect when you copy/paste.

NiFi's EL editor built in to the processor property text blocks can help identify when the EL format is wrong.
Screen Shot 2019-10-10 at 1.10.31 PM.png

In above you can see your NiFi EL statement as copied and pasted on line 3. You'll notice the color coding indicates an issue with the function's input parameters.
Line 1 has the properly formatted version of that same NiFi EL statement.

Be careful when using copy paste from some external editors.

Thank you,
Matt

View solution in original post

2 REPLIES 2

avatar
Explorer
${filename:substringBeforeLast(‘.’)}_${now():format("yyyy-MM-dd-HH-mm-ss")}.${filename:substringAfter('.')}

 This expression worked fine. Thanks

avatar
Master Mentor

Hello @girish6

 

Your first EL statement would work as well once you correct the single quote marks around the Z. 

Many outside text editors end up messing up the single quotes, so the NiFi EL ends up being incorrect when you copy/paste.

NiFi's EL editor built in to the processor property text blocks can help identify when the EL format is wrong.
Screen Shot 2019-10-10 at 1.10.31 PM.png

In above you can see your NiFi EL statement as copied and pasted on line 3. You'll notice the color coding indicates an issue with the function's input parameters.
Line 1 has the properly formatted version of that same NiFi EL statement.

Be careful when using copy paste from some external editors.

Thank you,
Matt