Author Topic: Simple script  (Read 5851 times)

Alyssa

  • Full Member
  • ***
  • Posts: 54
Simple script
« on: May 23, 2014, 06:08:38 PM »
Hello
I manage tons of photo picture in my computers so I am always looking for something to automatize things as much as possible. I am trying to create a batch processing to copy a file's filename into its "keyword" field (or even title field). I've been provided with a script that works under Google Picasa, which is the following

@echo off

:: initialise some variables that can be practical...
set BatFileDir=%~dp0

:: Start to do the real work
echo Busy processing file %1
"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:XPComment>exif:UserComment" %1
echo.

:: If an error occured, pause...
if %errorlevel% neq 0 pause

This script copy the "XP Comment" field into the "User comment" field, which I've needed badly in the recent past due to some view problems.
Now I want to modify the script a little bit and change it from that to filename > keyword / title field, is that possible?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #1 on: May 24, 2014, 05:59:00 AM »
Yes.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #2 on: May 24, 2014, 08:19:50 AM »
Is there some guide / index where I can see all names for each field?, for example, keyword field -> ?, filename -> ? -> comment field ?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #3 on: May 24, 2014, 12:03:21 PM »
I think that reading FAQs number 2 and 3 may help here.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #4 on: May 27, 2014, 05:36:40 PM »
Hello again

I've been looking there for hours, I can only find attributes that belong to the jpg image but not the actual file.

I tried random lines like "filename" or "namefile" it just won't work.
Is even file name a valid value?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #5 on: May 27, 2014, 07:11:13 PM »
Hi Alyssa,

If you're trying to confuse me, you are successful.

I've been looking there for hours

Looking where?  At the FAQ?  Did you try the commands that it suggested?

Quote
I can only find attributes that belong to the jpg image but not the actual file.

If you are looking for file attributes and their corresponding tag names, use this command:

exiftool -system:all -s FILE

where FILE is the name of your file.

Quote
Is even file name a valid value?

What do you mean by value?  "FileName" is a valid tag name.  It returns a value which is equal to the name of the file when used in a command like the one above.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #6 on: May 31, 2014, 10:37:18 PM »
Hello

I have "discovered" that the corrects tags I were looking was "-filename" for file name and "subject" for the tag field, however this leave me with another problem, with -filename the whole filename its copied along with his extension (e.g. image.jpg instead of just image), how you can cut the extension from being copied, its that even possible?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #7 on: June 01, 2014, 06:54:11 AM »
There are 2 ways to remove the extension from the file name when copying:

1) With a user-defined tag.  The sample config file ("config_files/ExifTool_config") in the full distribution contains the definition for a BaseName tag which does exactly this.  Read the comments in the config file for instructions on how to use a config file.  With this config file installed, you would use this command:

exiftool "-title<basename" FILE

2) With an advanced formatting expression.  For example:

exiftool "-title<${filename;s/(.*)\..*/$1/}" FILE

the above quoting is for Windows, on Mac/Linux you must use single quotes instead of double quotes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #8 on: June 01, 2014, 12:10:40 PM »
Thank you very much :) after some tries I managed to apply the code you suggested in the original script, now I am almost done with the script, I just have to add one last thing: the file creation date into the comments field.

I've been doing some researches and I've consulted pages like:
http://www.exiftool.org/filename.html#codes
http://www.exiftool.org/filename.html
http://unix.stackexchange.com/questions/128452/using-exiftool-to-add-exif-data-from-filenames

With the standard code:
"%BatFileDir%\exiftool.exe" -overwrite_original "-file:filecreatedate>exif:UserComment" %1
I get this date format: YYYY:MM:DD hh:mm:ss and + 02 GMT
I want the date to look like "DD/MM/YYYY hh:mm:ss",and after some random tries like:

echo Busy processing file %1
"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:UserComment<file:filecreatedate -d %%Y_%%m_%%d_%%H%%M%%%%-2c.%%%%e -r -P "> %1
echo.
(^With this I literally deleted the image file..... )

or

echo Busy processing file %1
"%BatFileDir%\exiftool.exe" -overwrite_original -d %Y%m%d_%H%M%%-c.%%e  "-exif:UserComment<file:filecreatedate"> %1
echo.

I figured out that I am putting the tags in the wrong place or format... I only get weird outputs or just error messages...


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #9 on: June 01, 2014, 01:57:33 PM »
Hi Alyssa,

echo Busy processing file %1
"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:UserComment<file:filecreatedate -d %%Y_%%m_%%d_%%H%%M%%%%-2c.%%%%e -r -P "> %1
echo.
(^With this I literally deleted the image file..... )

Ouch!  Yes.  This redirects the console output to overwrite the file: > %1 <-- BAD!!!!

...but I thought you wanted colons between the date fields (ie. %%Y:%%m:%%d, and similarly colons in the time.  Also, %%%%-2c.%%%%e will write literally into the UserComment, which I don't think you want, so you should remove this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #10 on: June 01, 2014, 03:18:14 PM »
Ok I changed this a bit,removed  %%%%-2c.%%%%e  and %%Y: instead of %%Y_ but it didn't change anything:

"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:xpsubject<file:filecreatedate -d %%d:%%m:%%Y_%%H:%%M:%%S -r -P" %1

It still displays the format as YYYY:MM:DD hh:mm:ss +GMT instead of DD:MM:YYYY hh:mm:ss (without GMT), even if I delete those attributes:
"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:xpsubject<file:filecreatedate" %1

Gives the exact output

Edit:
I've tried the model written in here:
http://ninedegreesbelow.com/photography/exiftool-commands.html

exiftool '-filename<CreateDate' -d %y%m%d_%H%M%S%%-c.%%le

But the file gets renamed  "mHS-1" instead of his creation date.
« Last Edit: June 01, 2014, 05:53:05 PM by Alyssa »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #11 on: June 01, 2014, 06:23:31 PM »
Hi Alyssa,

You still have a few problems.

"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:xpsubject<file:filecreatedate -d %%d:%%m:%%Y_%%H:%%M:%%S -r -P" %1

Your quoting is wrong, it should be:

"%BatFileDir%\exiftool.exe" -overwrite_original "-exif:xpsubject<file:filecreatedate" -d "%%d:%%m:%%Y_%%H:%%M:%%S" -r -P %1

Also, "%*" would be better than "$1" because then you could drop multiple files.

Quote
exiftool '-filename<CreateDate' -d %y%m%d_%H%M%S%%-c.%%le

But the file gets renamed  "mHS-1" instead of his creation date.

The quoting here is wrong for Windows.  You need double quotes instead of the single quotes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #12 on: June 01, 2014, 09:21:39 PM »
Hi
I sorted out most of the stuff I needed, but I have discovered an odd behaviour in exiftool.

I've created a shortcut of a exiftool.exe file placed in C:\ (With no other folders), for the path to be very short:
C:\exiftool.exe

I added this code then:
C:\exiftool.exe -overwrite_original "-xmp:description<${filename;s/(.*)\..*/$1/}" -overwrite_original "-subject<${filename;s/(.*)\..*/$1/}" -d %Y%m%d_%H%M%S%a%%-c.%%e "-filename<file:filecreatedate"

By drag & drop files in it this shortcut, it copied the file's names into the"Title" and "Tag" fields and then renaming the file with a YYYYMMDD_hhmmssDay format.

But I have noticed one thing, while it does correctly rename the files with their creation date it also resets it to the current time.
For example if I have a file created 2 hours ago and I drag & drop it on the first shortcut with that code added, it would be correctly renamed with a 2 hours ago timestamp, however IF I drag and drop the same file again in the shortcut it get renamed as if was created in that moment.

I create then another shortcut with just
C:\exiftool.exe -d %Y%m%d_%H%M%S%%-c.%%e "-filename<file:filecreatedate"
(Only using the last command in the list above)

This shortcut works as expected by renaming files with their creation date however it does not reset it like the above.

What's the cause behind file's create date being reset?

Also I have noticed that
-overwrite_original "-subject<${filename;s/(.*)\..*/$1/}"
Doesn't actually overwrite the original data in the "Tag"(Subject) field (unlike in the title / iptc:caption-abstract which actually erase/overwrite the existing data with the new one) but it adds it instead.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17044
    • ExifTool Home Page
Re: Simple script
« Reply #13 on: June 02, 2014, 07:19:42 AM »
But I have noticed one thing, while it does correctly rename the files with their creation date it also resets it to the current time.

FAQ 24 explains this.

Quote
Also I have noticed that
-overwrite_original "-subject<${filename;s/(.*)\..*/$1/}"
Doesn't actually overwrite the original data in the "Tag"(Subject) field (unlike in the title / iptc:caption-abstract which actually erase/overwrite the existing data with the new one) but it adds it instead.

It should:

Code: [Select]
> exiftool a.jpg -subject
Subject                         : Organize your library, Open Access, Metadata management
> exiftool a.jpg -overwrite_original "-subject<${filename;s/(.*)\..*/$1/}"
    1 image files updated
> exiftool a.jpg -subject
Subject                         : a

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

  • Full Member
  • ***
  • Posts: 54
Re: Simple script
« Reply #14 on: June 02, 2014, 08:18:16 AM »
Awesome, now its completed :)

Thanks for the help