[resolved] Extract part of a file name

Four Stars

[resolved] Extract part of a file name

Hi,
   I need to set a Global Variable based on part of a filename. For instance the file name could be SCC_converted_20141215.xml. I need the get the "SCC" part. It will always be the first part up to the first underscore. It won't always be the same length however. 
  What is the easiest way to do that?
Thanks,

Accepted Solutions
One Star

Re: [resolved] Extract part of a file name

If you know that the file name will contain an underscore and you want to pull anything before that then you can try this
get the file name and put it in a variable
row1.filename == null? null : (row1.filename.contains("-")? (row1.filename.substring(0,StringHandling.INDEX(row1.filename,"-"))) : <do something else>)
Hope this helps.

All Replies
One Star

Re: [resolved] Extract part of a file name

If you know that the file name will contain an underscore and you want to pull anything before that then you can try this
get the file name and put it in a variable
row1.filename == null? null : (row1.filename.contains("-")? (row1.filename.substring(0,StringHandling.INDEX(row1.filename,"-"))) : <do something else>)
Hope this helps.
Four Stars

Re: [resolved] Extract part of a file name

Perferct. Thanks. I got it to work.
One Star

Re: [resolved] Extract part of a file name

Hiii,
I have a file named as 'xyz_20160504_8000_T.txt'. Here the 8000 in the filename is the count of  number of rows present in the flatfile. I need to use a if condition where i need to check whether the filecount is equal to the nuumber of rows being uploaded. 
So please can anyone tell me how should I extract the number 8000 out of the filename so that I can compare it with the rows being uploaded.