Author Topic: Compare a metadata-field from different files  (Read 3226 times)

sinus

  • Global Moderator
  • *****
  • Posts: 4461
  • IMatch-User since 2001 (IMatch 3.6)
Compare a metadata-field from different files
« on: December 09, 2016, 11:05:27 AM »
Hi

For once, in these interestic times of IMatch Anywhere and so on, a trivial question.
And from the "good old Visual Basic".  ;D

I think, it is a trivial and easy question, but I come not on a solution.  :-\ :-[

I have a field ({File.MD.XMP::photoshop\TransmissionReference\TransmissionReference\0}).
This field has for, say, for 3 files a value, then for 4 another, for 2 another and so on.

This looks like here:

file1 Gordon
file2 Gordon
file3 Rosa Luxemburg
file4 Guess who
file5 Guess who
file6 Guess who
file7 Hard-cheese-Emmentaler

I want now numbering upwards these fields. For this I have a short script. This works fine, it appends numbers at the end, like
file1 Gordon-var-01
file2 Gordon-var-02
file3 Rosa Luxemburg-var-03
file4 Guess who-var-04

But I want this numbers not for all files, but for all files with the same value in the metadata-field.
So after running the script, it should looks like this:

file1 Gordon-var-01
file2 Gordon-var-02
file3 Rosa Luxemburg-var-01
file4 Guess who-var-01
file5 Guess who-var-02
file6 Guess who-var-03
file7 Hard-cheese-Emmentaler-var-01
...


means, for all files with the same value an upcounting number, for a new value it starts again with 0.

I think, it it easy, but maybe I am wrong, and it is not that easy.  :o

Here is the script, what works fine, but counts simply all files, also, if the value of the metadata-field changes.

Code: [Select]
Option Explicit

Sub Main
Debug.Clear

Dim selection As Files
Set selection = Application.GetFileWindow(imfwtCurrent).SelectedFiles
If selection.Count = 0 Then
MsgBox "Please select at least one file."
Exit Sub
End If

Dim f As File
Dim vals As TagValues
Dim data As TagData
Dim kundenname As String
Dim nummer As Long
nummer = 1

For Each f In selection
Set data = f.TagData
Set vals = data("XMP::photoshop\TransmissionReference\TransmissionReference\0")

If vals.Count = 0 Then
MsgBox "Mindestens eine Datei hat keinen K-Dateiname-Eintrag!"
Exit Sub
End If

  Dim oldval As String
oldval = vals(1)

vals.Set oldval & "-var-" & Format(nummer, "00")
nummer = nummer +1

data.Update vals
data.WriteBack

Next
End Sub

Does anybody of you has an idea or a solution?
Thanks in advance for any input.

BTW: I know, that WinWrap Basic will be not more part of IMatch in the near future  :'(






Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29729
Re: Compare a metadata-field from different files
« Reply #1 on: December 09, 2016, 02:01:04 PM »
You will have to implement a loop over all your files.
First sort all files by the metadata field.
Then run a loop, comparing the field to the field of the last file.
When the value changes, you reset your index back to 0.

Pseudo Code:


lastmeta = ''
firstfile = true
index = 0

for all f in files

  if (not firstfile AND lastmeta <> file.meta) then
    ' The metadata of this file is different from the last file ('group change') so we reset the index
    index = 0
  else
    index = index + 1
  end if

  ' Rename file, whatever...

  firstfile = false
end for


sinus

  • Global Moderator
  • *****
  • Posts: 4461
  • IMatch-User since 2001 (IMatch 3.6)
Re: Compare a metadata-field from different files
« Reply #2 on: December 09, 2016, 04:15:28 PM »
Thanks, Mario, for your input,

thought you have other interesting things to work on.  ;)

Your solution seems to be the correct one.
I tried it now here for 1.5 Std ... without success.  :-[

At home I will try my luck again.  8)
Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29729
Re: Compare a metadata-field from different files
« Reply #3 on: December 09, 2016, 05:39:10 PM »
Quote
I tried it now here for 1.5 Std ... without success.

I think when I first wrote such a script it took me days to figure it out...

sinus

  • Global Moderator
  • *****
  • Posts: 4461
  • IMatch-User since 2001 (IMatch 3.6)
Re: Compare a metadata-field from different files
« Reply #4 on: December 12, 2016, 11:13:43 AM »
Quote
I tried it now here for 1.5 Std ... without success.

I think when I first wrote such a script it took me days to figure it out...

Yep, Mario, I believe you  :) ... but maybe the difference is,  you do memorize things, what you did, much better then me.   :-\
I think, you could write a program in WinWrap much quicker then me.
Means, what you must look and lern, say, for 1 day, this takes me 10 days. Simply because your brain is somehow better to store and use such "mathematical" things.

So, every human has an aerea, where he/she is very good in. And you are really, I think, a master of programming.   :D

... Well, I tried this at home for another 2 hours. I decided then, to leave it, because it is not that important for me, I do simply select only files with the same value, then my script works.  ;D

Hence, no problem for me ... there are mostly several ways to Rome!  8)
Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29729
Re: Compare a metadata-field from different files
« Reply #5 on: December 12, 2016, 11:40:59 AM »
Quote
Simply because your brain is somehow better to store and use such "mathematical" things.

I was never good at maths. I was always good at programming and all things with machines and computers.

Please understand that I cannot write your script.
Even it I had the time (which I currently have not) I don't write programs for free out of principle. I make a living out of programming  ;D

sinus

  • Global Moderator
  • *****
  • Posts: 4461
  • IMatch-User since 2001 (IMatch 3.6)
Re: Compare a metadata-field from different files
« Reply #6 on: December 12, 2016, 11:46:39 AM »
Quote
Simply because your brain is somehow better to store and use such "mathematical" things.

I was never good at maths. I was always good at programming and all things with machines and computers.

Hm, so not math is your "thing", but programming and computers. Cool.

Please understand that I cannot write your script.
Even it I had the time (which I currently have not) I don't write programs for free out of principle. I make a living out of programming  ;D

Of course, this was not my intention and you have a lot other things to do, very logical to me. And at least, you have helped me with your "pseudo-code", thanks anyway.

But not to forget: we have here on the forum several scripters, sometimes also someone of them sees something like this and likes -depending on the time- to help.  ;D
Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29729
Re: Compare a metadata-field from different files
« Reply #7 on: December 12, 2016, 02:05:59 PM »
Yes, we have. But less and less.
Many things we needed scripts for back in IMatch 3 days are now built-in. And I'm adding new stuff based on user feedback all the time.

If somebody learns about programming these days, it will be about programming languages used for "the web". And this means JavaScript HTML, plus some other languages used for server-side programming. Not BASIC.

This makes it easier for me to retire the aging and expensive Basic Scripting engine in IMatch. I will replace it with support for JavaScript, HTML etc. using IMatch Anywhere technology.


sinus

  • Global Moderator
  • *****
  • Posts: 4461
  • IMatch-User since 2001 (IMatch 3.6)
Re: Compare a metadata-field from different files
« Reply #8 on: December 12, 2016, 03:07:30 PM »
Yes, we have. But less and less.
Many things we needed scripts for back in IMatch 3 days are now built-in. And I'm adding new stuff based on user feedback all the time.

If somebody learns about programming these days, it will be about programming languages used for "the web". And this means JavaScript HTML, plus some other languages used for server-side programming. Not BASIC.

This makes it easier for me to retire the aging and expensive Basic Scripting engine in IMatch. I will replace it with support for JavaScript, HTML etc. using IMatch Anywhere technology.

Yep, that is why I TRY to lern Javascript.  8)

I have still made some scripts, one a countdown für events (not really IMatch-related, but first tried there).
Then a memory, based on your really cool "tiles".

And a simply workflow for our system here.

And finally a "visual pendant to Meta-data-panel", where I am free to display Metadata, how I like. But of not writeable and of course not that sophisticated like your native panel.

After all, since I lerned to write some Winwrap - scripts and now some JavaScripts, for me WinWrap is much easier and more logical. For example I can easy read and write some stuff on my computer.
What I can do with Javascript also, but much more complicated.

But this is only my feeling, and yes, I know, that JS is much better and still one of the programming-system of the future. Togethere with html5 and css. But of course, I am sure, there is new stuff outside, from what I have not a faint clue.  :o

After all, I am simply a photographer.  ;D
Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29729
Re: Compare a metadata-field from different files
« Reply #9 on: December 12, 2016, 03:40:04 PM »
JavaScript runs under the control of your web browser or whatever JavaScript engine you use (Node.js etc.).
This means that there are many security concerns, e.g. access files on your local system is not possible straight out of the box.

JavaScript is a programming language for the web. It makes it super-easy to load and store data in a cloud (Google, Microsoft, Amazon, Dropbox) but very hard to store data in your local file system. It is no all-purpose programming language.

For the few occasions where a JavaScript running in IMatch needs access to the file system, I plan to add support for it in IMatch WebServices embedded in IMatch. Similar to the XMLWriter class we have now for Basic, which makes it easy to create and write XMP files. Or the ReadTextFile/WriteTextFile or ClipboardCopy methods of the Application class.

Instead of reading a text file manually from JavaScript, you ask IMWS to load it to you and to "give" it to your JavaScript as a string. And when you need to write a text file, you send IMWS the text and tell it where to store it. Easy to do on my end (in IMWS) and easy to use from JavaScript.

I envision this would look like this in JavaScript:

Code: [Select]
var text = "This is the text of my file\r\n";
text += "A second line of text, just for fun.\r\n";

IMWS.save(url+ "/textfile/save",
{
    data: text,
    filename: 'c:\temp\test.txt',
    encoding: 'UTF8'
});

Or, to read a file from your disk:

Code: [Select]
var text;

IMWS.get(url+ "/textfile/load",
{
    filename: 'c:\temp\test.txt',
}).response(data) {
  text = data.
}

Not too hard to learn. It's always IMWS.get() or IMWS.save() or IMWS.delete() and then name of the method you call "/textfile/save" or "/textfile/load" plus the parameters you need to provide.

And this works the same whether you run it "inside IMatch" from a script running in the AppPanel or you run it from a script in your web browser, independently from IMatch for Windows. This script will work even on your tablet when you are 500 miles away from your computer - as long as you can connect to IMatch WebServices.

Of course there will be security measures when your script is not running "inside" IMatch, for example your script will have to authenticate (log-in) before it can ask IMWS to deliver a text file.

sinus

  • Global Moderator
  • *****
  • Posts: 4461
  • IMatch-User since 2001 (IMatch 3.6)
Re: Compare a metadata-field from different files
« Reply #10 on: December 12, 2016, 04:48:55 PM »
Thanks, Mario
for this info.

Yes, looks good and not that hard, you are right.

So I am on the right way, if I am lerning JS.  ;D
Best wishes from Switzerland! :-)
Markus