INTERACT FORUM

Please login or register.

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

Author Topic: Smartlist to validate filename  (Read 2038 times)

pahunt

  • World Citizen
  • ***
  • Posts: 236
Smartlist to validate filename
« on: May 22, 2014, 04:50:23 pm »

I'm trying to put together a smartlist that will show any media which has a filename that does not match what I expect it to be. This is so that I can catch things that I haven't run the rename tool on, however I am struggling to make it work.

Here's what I've done:

1. Created a new user field called "Correct Filename" that calculates what the correct filename should be.
2. Created a smartlist with the expression with criteria of Filename | is not | [Correct Filename]

However no results are returned. I suspect the issue is that you can't user field names on the right-hand side of an expression but is there some way I can achieve the desired result?

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Smartlist to validate filename
« Reply #1 on: May 22, 2014, 04:59:24 pm »

The easiest method will be to use the IsEqual() function.

Code: [Select]
IsEqual([Filename], [Correct Filename], 1)
That will output 1 if they match, and 0 if they don't (case insensitive).

If you wrap it in an If() you can output other values instead (if you prefer it to have more nicely formatted output).  The related-but-different Search system supports comparison operators, but since Expressions always evaluate as strings, there's no clear way to evaluate equality (or greater than/less than, etc) without using a specific function for the task.

Hence, IsEqual(), IsEmpty(), IsMissing(), IsRange(), etc.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

pahunt

  • World Citizen
  • ***
  • Posts: 236
Re: Smartlist to validate filename
« Reply #2 on: May 22, 2014, 05:07:18 pm »

Of course, that will do the trick nicely. Thanks

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Smartlist to validate filename
« Reply #3 on: May 22, 2014, 07:38:04 pm »

You are correct, that fields won't be evaluated on the RHS of the search query.

You need to use an expression-based search query for this:

Paste this fragment into the Set rules for file display's Import/Export dialog:

   [=isequal([Filename], [Correct Filename], 1)]=1

The key construct is this:

  [=<expr>]=1

and the <expr> evaluates to 1 for true and anything else otherwise.
Logged
The opinions I express represent my own folly.

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Smartlist to validate filename
« Reply #4 on: May 22, 2014, 08:13:01 pm »

You are correct, that fields won't be evaluated on the RHS of the search query.

Now it dawns on me that this was, of course, correct.  The problem is that =value has to be a constant.

But the net effect is the same.  You don't need to include the =1 because in a search IsEqual() evaluates to 1 for True anyway.  I read the question as related to a displayed calculated field or expression column.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

pahunt

  • World Citizen
  • ***
  • Posts: 236
Re: Smartlist to validate filename
« Reply #5 on: May 23, 2014, 01:57:42 am »

Well to be clear, the idea I took away from glynor's answer was to create a second calculated field called [Has Correct Filename] that used IsEqual to compare [Filename] with [Correct Filename] and then use that field as the basis for the smartlist with a criteria of [Has Correct Filename] | is | 0.

Thanks for both your help though, I now have exactly what I need.

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2239
Re: Smartlist to validate filename
« Reply #6 on: May 23, 2014, 03:59:17 am »

Paul, would you mind posting the complete smart list expression for me?

I'd like to see the finished product.

Thanks ..  8)
Logged
MC31, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

pahunt

  • World Citizen
  • ***
  • Posts: 236
Re: Smartlist to validate filename
« Reply #7 on: May 23, 2014, 04:12:30 am »

The [Correct Filename] user field expression is:

Code: [Select]
\\GEORGE\Audio\[Media Sub Type]\[Artist]\[Album]\[Name].[File Type]
The [Has Correct Filename] user field expression is:

Code: [Select]
IsEqual([Filename], [Correct Filename], 1)
The smartlist criteria is:

Code: [Select]
[Media Type] | is | Audio
[Has Correct Filename] | is | 0

EDIT: I've just noticed that there are some issues with this still, I can see why but I'm not sure how to resolve them. Take the Arctic Monkeys track "R U Mine?" from the album "AM". The [Correct Filename] expression generates:

Code: [Select]
\\GEORGE\Audio\Music\Arctic Monkeys\AM\R U Mine?.flac
but the actual filename is:

Code: [Select]
\\GEORGE\Audio\Music\Arctic Monkeys\AM\R U Mine_.flac
Obviously when the rename happens, some magic goes on to convert characters that are invalid in filenames, such as ? to an underscore.

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2239
Re: Smartlist to validate filename
« Reply #8 on: May 23, 2014, 07:42:00 am »

...

but the actual filename is:

Code: [Select]
\\GEORGE\Audio\Music\Arctic Monkeys\AM\R U Mine_.flac
Obviously when the rename happens, some magic goes on to convert characters that are invalid filenames, such as ? to and underscore.

By observation, that's an MC naming standard. For a question mark, I've used an upside down character before - ¿ - and that works. Now I just hang with the standard deal.

Thanks for sharing.
Logged
MC31, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Smartlist to validate filename
« Reply #9 on: May 23, 2014, 10:12:07 am »

Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

pahunt

  • World Citizen
  • ***
  • Posts: 236
Re: Smartlist to validate filename
« Reply #10 on: May 23, 2014, 10:41:35 am »

Clean() mode 3.

That got me very close but there was still a case that didn't work. For reference, after adding the Clean function my [Correct Filename] function was

Code: [Select]
\\GEORGE\Audio\[Media Sub Type]\Clean([Artist], 3)\Clean([Album], 3)\Clean([Name], 3).[File Type]
However for the DJ Shadow album "Endtroducing...." I got a [Correct Filename] of

Code: [Select]
\\GEORGE\Audio\Music\DJ Shadow\Endtroducing....\Best Foot Forward.flac
But the actual filename generated when using the rename tool is this (note the missing dots)

Code: [Select]
\\GEORGE\Audio\Music\DJ Shadow\Endtroducing\Best Foot Forward.flac
As you can see it is stripping the trailing dots and so I had the same problem with R.E.M. being generated as R.E.M

Therefore I needed to strip the trailing dots from folder names (not the filename though) and fortunately enough the RemoveCharacters() function can do exactly that. So my finished expression is now

Code: [Select]
\\GEORGE\Audio\[Media Sub Type]\RemoveCharacters(Clean([Artist], 3), ., 2)\RemoveCharacters(Clean([Album], 3), ., 2)\Clean([Name], 3).[File Type]
Thanks for everyone's help :)
Pages: [1]   Go Up