EXIF Info..

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
aimy
Posts: 181
Joined: 26 Feb 2007 15:44

EXIF Info..

Post by aimy »

I'm really sorry if this topic has been discussed.. But based on my search, most results are only concern about the date and time.

But what I really want is to rename file based on other EXIF info e.g. camera model.

So, is it possible?

Thank you so much.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: EXIF Info..

Post by Stefan »

aimy wrote:But what I really want is to rename file based on other EXIF info e.g. camera model.
Hy there.

In XYplorer help > Advanced Topics > Varables
is only this found
<dateexif> EXIF date of the current list item


But here is >> "Exiv2, a command line utility", found at >> http://www.exiv2.org/#util


Example:
http://www.exiv2.org/sample.html

Code: Select all

$ exiv2 img_1771.jpg

File name       : img_1771.jpg
File size       : 32764 Bytes
MIME type       : image/jpeg
Image size      : 480 x 360
Camera make     : Canon
Camera model    : Canon PowerShot S40
Image timestamp : 2003:12:14 12:01:44
Image number    : 117-1771

With this utility one could create an script like

Dummy code:

Code: Select all

$EXIF =  exiv2 <curitem>

  For Each Item In $EXIF
  {
     if found "Camera model"
     $output = split line at : colon
  }
  rename file  $output*
If you need more help just ask.
Maybe someone have already played around with Exiv2?

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: EXIF Info..

Post by Stefan »

Ah, i forget about properties()

See this info > http://www.xyplorer.com/xyfc/viewtopic. ... 592#p39592
(There is mentioned an other command line exif tool too: ExifTool: http://www.sno.phy.queensu.ca/~phil/exiftool/)

The syntax of script command property you will find in help.
That combined with an rename command could be like this
working test command

Code: Select all

$CamMod = property("CameraModel");
   rename b, "$CamMod - *", p;
For more info see XY help > Advanced > Scripting commands

The known properties your system provide you can see under menu "Tools > Config > File Info Tips" at the right.

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Info..

Post by aimy »

Stefan wrote:Ah, i forget about properties()

See this info > http://www.xyplorer.com/xyfc/viewtopic. ... 592#p39592
(There is mentioned an other command line exif tool too: ExifTool: http://www.sno.phy.queensu.ca/~phil/exiftool/)

The syntax of script command property you will find in help.
That combined with an rename command could be like this
working test command

Code: Select all

$CamMod = property("CameraModel");
   rename b, "$CamMod - *", p;
For more info see XY help > Advanced > Scripting commands

The known properties your system provide you can see under menu "Tools > Config > File Info Tips" at the right.
Thank you so much... :D

So now, I have a script button with this command..

Code: Select all

$CamMod = property("CameraModel");
   rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod", p;
that would rename a picture file 08102010066.jpg for example to 20101008.211954~08102010066_N97 mini.jpg

But what if I want to cater a case where the picture missed the EXIF info?

In this case for example, it would be renamed as ~08102010066_.jpg which is not proper. So, I want it to retain the original filename if no EXITFfound in the file. Could I do that within a one script?

Thanks a lot.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: EXIF Info..

Post by Stefan »

aimy wrote:But what if I want to cater a case where the picture missed the EXIF info?
So, I want it to retain the original filename if no EXITFfound in the file.
Could I do that within a one script?
Currently i have no idea how to code this in a proper way.

This script will handle each file at its one
and ask you if the new name is correct.
This is handled by the "p" switch in the rename() command.
I expected to see all selected files in the renaming preview
instead showing an preview for every single file.
You can remove the "p" after you have checked a few files if it worked correct, but...
I'am sure someone will have an better idea.


And, if i cancel the rename-preview-dialog called from the script,
the script-debugging dialog appears telling me the renaming was canceled :(
If i cancel an renaming-dialog called from context menu i get no such info.

Code: Select all

$list = get("SelectedItemsPathNames", "|");

  $index=1;
   
  while(true)
  {
     //get one after the other file from file list $file:
     $file = gettoken($list, $index, "|");
     if ($file==""){break;}
     
     //read property from actual file:
     $CamMod = property("CameraModel", $file);
      
     //trim space and tabs around the reported property:
     $CamMod = regexreplace($CamMod, "\s*|\t*(.*)\s*|\t*", "$1");
     //msg "Debug:  #$CamMod#",1;
       
     
     //rename only if there is no emtpy property:
     if ($CamMod != "")
     {
          rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod", p, $file;
        //rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod",  ,  $file;
     }
     
  //next file:
  incr $index;
  if ($index > 1000){break;} //prevent infinity loop while script testing
  }
Last edited by Stefan on 11 Feb 2011 21:06, edited 1 time in total.

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Info..

Post by aimy »

Stefan, thanks a lot for your effort, I really appreciate.. :)

Yeah, I just noticed that my simple script above would not preview the file name correctly if I select multiple files.
2011-02-10_030632.gif
2011-02-10_030632.gif (50.05 KiB) Viewed 3267 times
It would only show up to the dateexif renaming, not the camera model. :(
2011-02-10_030724.gif
2011-02-10_030724.gif (28.76 KiB) Viewed 3267 times

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Info..

Post by aimy »

hi zero, dont u feel to lend a help? :P

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: EXIF Info..

Post by Stefan »

You may also use an third-party tool called Siren as additional renamer tool

Example:


FROM:
DSC00090.JPG
TO:
20080818_184633~DSC00090_K800i.JPG

First read and do this >>> http://scarabee-software.net/forum/viewtopic.php?id=228
To start Siren from XYplorer dir paste this into the XYplorer Addressbar:
::run """<xypath>\Siren.exe"" <selitems>"; //rename the items currently selected

Now you can see an preview of all files in that folder
and start renaming only of the in XY selected files in Siren.


Your expression for Siren for your case would be something like:
%Xdo~%b_%Xmo.%e


but if there is no exif info about camera model
this would lead to an result like:
~DSC00090_.JPG

So i add an second expression
to catch names with an leading '~' and an trailing '_'
and remove this signs again:

%Xdo~%b_%Xmo.%e;%fc(s/^~(.+)_/\1/)

Now take an look at the preview and start renaming.
Of course that can be done with XYplorer itself too, but the advantage of an tool like Siren is the preview.



Short Explanation of the expression:
%Xdo~%b_%Xmo.%e;%fc(s/^~(.+)_/\1/)

%Xdo >>> an date (i hope the taken date?)
~
%b >>> base name without extension
_
%Xmo >>> exif info camera
.
%e >>> original extension
; >>> delimiter for next expression
%fc >>> complete (calculated) filename
(s/^~(.+)_/\1/) >>> regular expression: find "~" than (one-or-more of any sign) till an "_", then replace with what is matched between the "(...)"

Your result may vary if your file names have an different format / position of signs.


Hope that makes sense and helps :D

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Info..

Post by aimy »

Thank you so much stefan.. May God bless you.. :D

But I was wondering.. Since u have proven that XYplorer could read the CameraModel property, why it is so difficult to achieve batch rename?

I've tried many times and many ways playing around with that property("CameraModel") but to no avail. It will always read the first selected file info only :(

I'm not really good at programming, but I like to do it when I know that it can be achieved and understand the script a litlle bit.

So in this case, since the objective is very straight-forward and simple.. I dont see why I do have to go for a hard way of achieving it? :(

Anyway, thank you so much again for your assistance.

Before I go to that solution, I just would like to know.. Is it true that XYplorer alone could not achieve my goal?

Thank you.

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: EXIF Info..

Post by admin »

aimy wrote:Thank you so much stefan.. May God bless you.. :D

But I was wondering.. Since u have proven that XYplorer could read the CameraModel property, why it is so difficult to achieve batch rename?

I've tried many times and many ways playing around with that property("CameraModel") but to no avail. It will always read the first selected file info only :(

I'm not really good at programming, but I like to do it when I know that it can be achieved and understand the script a litlle bit.

So in this case, since the objective is very straight-forward and simple.. I dont see why I do have to go for a hard way of achieving it? :(

Anyway, thank you so much again for your assistance.

Before I go to that solution, I just would like to know.. Is it true that XYplorer alone could not achieve my goal?

Thank you.
Very easy:

Code: Select all

WRONG: rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod", p, $file;
RIGHT: rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, p, $file;
The point is that <dateexif yyyymmdd.hhnnss> should only be resolved within rename, not before. Therefore it has to be quoted in single-quotes.

EDIT: Just assuming that this was the problem. I did not really read the whole thread....

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: EXIF Info..

Post by Stefan »

aimy wrote:But I was wondering.. Since u have proven that XYplorer could read the CameraModel property, why it is so difficult to achieve batch rename?
:shock: :?: Yes, XYplorer can!

I have provided you an working script above > http://www.xyplorer.com/xyfc/viewtopic. ... 045#p57045

The only problem i had was that i didn't have an preview how the files would be renamed.

I have set the "p" option but this show the preview for each and every file
instead for all (selected) files.

But if you didn't need the preview just remove this "p" from the command (after you have seen how the script works)

The second issue i mentioned was that the debug dialog appears if i cancel the script.
But that is only an cosmetic issue, just forget this.

The only advantage of an external tool like SIren is the preview bevor renaming.

We can code our own preview with an workaround, but.... using Siren is more nifty IMHO.

You chose.

Have you tested that script? Didn't work it for you? What is still your "problem"?


CU

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Info..

Post by aimy »

admin wrote:
aimy wrote:Thank you so much stefan.. May God bless you.. :D

But I was wondering.. Since u have proven that XYplorer could read the CameraModel property, why it is so difficult to achieve batch rename?

I've tried many times and many ways playing around with that property("CameraModel") but to no avail. It will always read the first selected file info only :(

I'm not really good at programming, but I like to do it when I know that it can be achieved and understand the script a litlle bit.

So in this case, since the objective is very straight-forward and simple.. I dont see why I do have to go for a hard way of achieving it? :(

Anyway, thank you so much again for your assistance.

Before I go to that solution, I just would like to know.. Is it true that XYplorer alone could not achieve my goal?

Thank you.
Finally you come to save us.. :mrgreen:

Thanks a lot admin.
Very easy:

Code: Select all

WRONG: rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod", p, $file;
RIGHT: rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, p, $file;
The point is that <dateexif yyyymmdd.hhnnss> should only be resolved within rename, not before. Therefore it has to be quoted in single-quotes.

EDIT: Just assuming that this was the problem. I did not really read the whole thread....

aimy
Posts: 181
Joined: 26 Feb 2007 15:44

Re: EXIF Info..

Post by aimy »

Stefan, as admin have pointed out, the only mistake in your script is on the rename line.

So, this is the corrected version of your script..

Code: Select all

$list = get("SelectedItemsPathNames", "|");

  $index=1;
   
  while(true)
  {
     //get one after the other file from file list $file:
     $file = gettoken($list, $index, "|");
     if ($file==""){break;}
     
     //read property from actual file:
     $CamMod = property("CameraModel", $file);
      
     //trim space and tabs around the reported property:
     $CamMod = regexreplace($CamMod, "\s*|\t*(.*)\s*|\t*", "$1");
     //msg "Debug:  #$CamMod#",1;
       
     
     //rename only if there is no emtpy property:
     if ($CamMod != "")
     {
          rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, p, $file;
        //rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod",     $file;
     }
     
  //next file:
  incr $index;
  if ($index > 1000){break;} //prevent infinity loop while script testing
  }
  
Thanks a lot again for your effort.

Now, there's no more error in the script.. It's just that... As you've mentioned before, this script will preview the renamed files one by one. Just imagine if I need to rename thousand of files and i need them to be previewed all at once. So now, how do I modify the script so that it can preview the renamed files normally just like with this simple rename command..

Code: Select all

rename, '<dateexif yyyymmdd.hhnnss>~*', p;
That's all I need.

Thank you.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: EXIF Info..

Post by Stefan »

aimy wrote:Stefan, as admin have pointed out, the only mistake in your script is on the rename line.
So, this is the corrected version of your script..
[...]
Now, there's no more error in the script.. It's just that...
Ahh, OK. Fine. Thanks Don for the help!

As you've mentioned before, this script will preview the renamed files one by one. Just imagine if I need to rename thousand of files and i need them to be previewed all at once. So now, how do I modify the script so that it can preview the renamed files normally just like with this simple rename command..
:D OK once more. Slowly... :wink:

The "p" char in that command
rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, p, $file;
is the option to enable that preview dialog.

What is "normally"?
Since we have to work on file by file to get the property for each single file
this rename command is invoked for each file,and so that preview is shown for each file too.

I don't know how to show an preview for all files from an script.
(Only with an workaround and collect all renaming strings and provide
them before real renaming with text() command or like that.)

To get rid of that preview for every file all you have to do is
to remove this p (leave the coma-delimiter) from that command,
as the commented line shows you:

Code: Select all

          rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, p, $file;
        //rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod",  , $file;  
Just delete the line with the p
and remove the comment signs "//" from the remaining line.
Then you get no preview window anymore.


And BTW, an second pitfall in my script is the debug line to end the script after 1000 files.
You can just remove this whole line if you are sure the script works for your case:

Code: Select all

     
  if ($index > 1000){break;} //prevent infinity loop while script testing
  


Here as an support is the whole script without those mentioned error handling lines:

Code: Select all

$list = get("SelectedItemsPathNames", "|");

  $index=1;   
  while(true)
  {
      //get one after the other file from file list $file:
      $file = gettoken($list, $index, "|");
      if ($file==""){break;}
     
      //read property from actual file:
      $CamMod = property("CameraModel", $file);
      //trim space and tabs around the reported property:
      $CamMod = regexreplace($CamMod, "\s*|\t*(.*)\s*|\t*", "$1");
       
       //rename only if that property is not empty :
      if ($CamMod != "")
      {
           rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, , $file;
      }
     
   //process next file:
   incr $index;
   }

Hope this makes it somehow clearer :)

If anyone have more question(s)... just ask!
Last edited by Stefan on 11 Feb 2011 21:10, edited 1 time in total.

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: EXIF Info..

Post by admin »

Stefan wrote:To get rid of that preview for every file all you have to do is
to remove this p include the coma-delimiter from that command,
as the commented line shows you:

Code: Select all

          rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, p, $file;
        //rename b, "<dateexif yyyymmdd.hhnnss>~*_$CamMod",     $file;  
Just delete the line with the p
and remove the comment signs "//" from the remaining line.
Then you get no preview window anymore.
No, the comma has to stay:

Code: Select all

rename b, '<dateexif yyyymmdd.hhnnss>~*_' . $CamMod, , $file;
BTW, if $CamMod is the same for each file, the script can be done much easier, and with a summary preview for all files...

Post Reply