Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Adding timestamp to the file name before extension

Solved Go to solution

Adding timestamp to the file name before extension

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

Accepted Solutions
Highlighted

Re: Adding timestamp to the file name before extension

Master Guru

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

2 REPLIES 2

Re: Adding timestamp to the file name before extension

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

 This expression worked fine. Thanks

Highlighted

Re: Adding timestamp to the file name before extension

Master Guru

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

Don't have an account?
Coming from Hortonworks? Activate your account here