INTERACT FORUM

Please login or register.

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

Author Topic: creating rules for folder's and file names.  (Read 1676 times)

666JackTheKnife666

  • World Citizen
  • ***
  • Posts: 150
creating rules for folder's and file names.
« on: May 10, 2009, 09:17:44 pm »

I am having trouble figuring out how to create the rules for folders and file names.
specifically I want to know how to create if statements ie if tag = x do this type rules.
I keep looking around in the help files and I am not finding anything I can understand.
thx..
Logged

Frobozz

  • Citizen of the Universe
  • *****
  • Posts: 641
  • There is a small mailbox here.
Re: creating rules for folder's and file names.
« Reply #1 on: May 11, 2009, 12:59:29 am »

Do you have experience writing complex functions for spreadsheets (functions involving if statements and such)?

The way MC does expressions is similar to spreadsheets.  Expressions are all in one line of text, functions get nested within other functions, you can get several layers deep in parenthesis.  It can be confusing trying to decipher.

The list and explanation of available functions is here: Media Center expression language

The general layout for an if statement is: If(TEST_EXPRESSION, WHAT_HAPPENS_WHEN_TRUE, WHAT_HAPPENS_WHEN_FALSE)

Here's an example of my directory naming rule:
[library]\[Album Artist (auto)] - [Album]If(IsEmpty([Disc #],1),,-PadNumber([Disc #],2)) [[File Type]]

Here's an example of my file naming rule:
Mid([Album Artist (auto)],0,20)-Mid([Album],0,20)-If(IsEmpty([Disc #],1),,PadNumber([Disc #],2))-PadNumber([track #],2)-Mid([Name],0,20)

Let's take an example from my directory naming rule
If(IsEmpty([Disc #],1),,-PadNumber([Disc #],2))

What it does.
If the [Disc #] field is empty it prints out nothing
If the [Disc #] field is not empty it prints out a dash "-" and the disc number padded to two digits

It is a bit confusing with the nested parenthesis.  It is easier to follow if you use a text editor that is designed for programming text.  The better editors will have a function that highlights matching braces and parenthesis.

Alternatively, you can edit the expression in a regular text editor and indent each level of parenthesis.  Something like this:
Code: [Select]
If(
  IsEmpty(
    [Disc #],1
  )
  ,
  ,-PadNumber(
    [Disc #],2
  )
)
That makes it easier to keep track of the parenthesis while creating and editing the expression.  Then when you are done you edit it back to a single line of text and paste it in Media Center.


Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 9140
Re: creating rules for folder's and file names.
« Reply #2 on: May 11, 2009, 01:23:56 am »

There's three topics on the wiki that might help.

"if tag = x do this"

if(isequal([tag],x,1),

This asks "does [tag] = x or X" The '1' specifies case insensitivity. After asking the question, you must give instructions for true and false. True always comes first...

I have an x,

followed by false...

I don't have an x)

giving you: if(isequal([tag],x,1),I have an x,I don't have an x)

There's nothing to stop you asking further "If" questions instead of giving definitive answers, though once you get into that, it can get quite complex quite quickly. If you do end up going down that route, my advice is to compose your expression in a text editor first, then copy and paste into MC. It's much easier to keep track of what's going on that way.

This post will give you an idea of just how complex you can get.
While it took me a while to get these just right, they have served me well for years, more than paying back the time invested in their creation.

-marko.

Frobozz replied while I was composing, I'll post anyway as two answers may be as good as one ;)

666JackTheKnife666

  • World Citizen
  • ***
  • Posts: 150
Re: creating rules for folder's and file names.
« Reply #3 on: May 11, 2009, 02:09:22 am »

thank you vary much, this help a ton..
Logged
Pages: [1]   Go Up