INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Functions not returning expected values in "Rename, move & copy files"-solved  (Read 4290 times)

terrym@tassie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 505

I was trying to write an a rename expression which used the IsEmpty function on a string field in "Rename, move & copy files" and I found that it does not return a 1 if the string value is empty.
E.g In filename rename [Name]-If(IsEmpty([Composer]),,[Composer]).mp3 so that if [Composer] field is blank it is not included in filename- it returned 'track name-Unknown Composer.mp3' if the [Composer] field was blank or 'track name-Sibelius.mp3' if the [Composer] field was populated (Sibelius in the example).

Digging a bit further, putting just IsEmpty([Composer]) returns 0.mp3 if the [Composer] field is empty or 0.mp3 if it is populated.
In an expression column IsEmpty([Composer]) returns 1 if the field is empty and 0 if it is populated.
 
Even stranger if I put Length([Composer]) it returns 8.mp3 if the [Composer] field is "Sibelius" (fair enough) and 16.mp3 if the [Composer] field is empty (I think it should return 0- and does in a normal expression column).

This behaviour happens on any string type field, [Producer], [Popularity] etc.

Any ideas?
Logged
Good manners cost nothing.
Bad manners can cost you your reputation
― B.D.Hawkey

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2663
Re: Functions not returning expected values in "Rename, move & copy files"
« Reply #1 on: September 10, 2013, 10:35:16 pm »

Try:

[Name]-If(IsEmpty([Composer],1),,[Composer]).mp3
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Functions not returning expected values in "Rename, move & copy files"
« Reply #2 on: September 10, 2013, 10:40:42 pm »

There was a recent explanation about this very topic:

   http://yabb.jriver.com/interact/index.php?topic=83464.0
Logged
The opinions I express represent my own folly.

terrym@tassie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 505
Re: Functions not returning expected values in "Rename, move & copy files"
« Reply #3 on: September 10, 2013, 11:56:45 pm »

Thanks MrC I know where I was going wrong now!

It should be If(IsEmpty(field(Composer,0)),,[Composer]) or even more conventionally If(IsEmpty([Composer,0]),,[Composer])

I also understand why I was getting Length([Composer]) returning 16 characters- Unknown Composer=16 characters  DOH!

Thanks again!
Logged
Good manners cost nothing.
Bad manners can cost you your reputation
― B.D.Hawkey

javidan

  • Junior Woodchuck
  • **
  • Posts: 76
Re: Functions not returning expected values in "Rename, move & copy files"
« Reply #4 on: September 11, 2013, 08:42:18 am »

Thanks MrC I know where I was going wrong now!

It should be If(IsEmpty(field(Composer,0)),,[Composer])

I also understand why I was getting Length([Composer]) returning 16 characters- Unknown Composer=16 characters  DOH!

Thanks again!

Hi Terry,

The isEmpty() function of JRiver threw me into a massive loop when i first encountered it myself. i.e. It does not work as intuitively as you would like it.

Therefore I have stopped using it for what you are trying to achieve and replaced it with isEqual([FIELDNAME],Unknown,7) instead.
I am not sure what goes on behind the scenes if you are talking about script efficiency but it is a not as "readible" as isEmpty but still doesn't confuse me.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.

The IsEmpty() function does exactly what it says and should do.  Rather, it is the expression language that uses the formatted version of a field by default that is causing the confusion.  Use [field,0] when you want to test the raw data assigned to the field, because by default you're getting [field,1] behavior.  It is OK to test against the formatted output, but in certain causes you'll end up having to fix your expressions when used in other circumstances.
Logged
The opinions I express represent my own folly.

javidan

  • Junior Woodchuck
  • **
  • Posts: 76

The IsEmpty() function does exactly what it says and should do.

Will it help, if there were more examples in the documentation of when we use isEmpty() as opposed to isEqual(Unknown)?

I believe I have tried it on several occassions where I tried isEmpty([artist]) and it returned 1 when I specifically cleared the values in those tags just before trying.

I could not find documentation of [field, 0] or [field, 1] and how it affects the functions, what I know about the expression today is often my own experience through guidance from individuals like yourself who helped me.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.

How about a careful reading of the three small sub-sections at:

   http://wiki.jriver.com/index.php/Media_Center_expression_language#Fields

and let me know if it isn't clear.
Logged
The opinions I express represent my own folly.

javidan

  • Junior Woodchuck
  • **
  • Posts: 76

Thanks again Mr C,

I will do that, that's the least I can do to see if I can contribute now that I am aware that most of our scripting documentation has been done by JRiver users like you.
Logged
Pages: [1]   Go Up