ExifTool Forum

ExifTool => Newbies => Topic started by: Alyssa on July 24, 2014, 10:36:02 AM

Title: Almost complete script needs some fixing
Post by: Alyssa on July 24, 2014, 10:36:02 AM
Hello

I've been trying to assemble a working script to add file's create date into its own comments fields, using some custom adjustments, well, I almost made it work but apparently isn't still working 100%.

The script its the following:

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%A]%%" "-exif:XPComment<file:filecreatedate" -P
(I use scripts directly on shortcuts, hence the C:\exiftool.exe)

This is what I get:
24/07/2014 Custom Text 15:40:52[A]%

This is what I would like to get
24/07/2014 Custom Text 15:40:52[Thursday]
(Note the uppercase letter"T", I would like to have the first letter uppercase if possible)

I've tried to adjust the code multiple times but that's the best I got so far, what's wrong in the code?

Thanks in advance
Title: Re: Almost complete script needs some fixing
Post by: Hayo Baan on July 24, 2014, 03:23:47 PM
First you'll need to get rid of the %%; that is the cause of the % at the end of your text.

For the rest, there doesn't seem to be anything wrong with the command. It seemed to work just fine me. I'm on a Mac though and there the shell has different rules for interpreting arguments. In your case it could be that the [ and ] get interpreted by your shell into something special. You may try escaping them e.g., \[ and \]. Or try a different character altogether.

For testing purposing, it's probably better to use the -p option to print the output instead of writing it to the file first:
exiftool -d "%d/%m/%Y Custom Text %H:%M:%S[%A]" -p '${file:filecreatedate}'
This way you can validate the result before writing the file.

Hope this helps,
Hayo
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 24, 2014, 04:01:06 PM
Sorry but for some reason now the script doesn't even work anymore, I don't known what happened, but it doesn't write anything on the file (I tried to change the " ' " to " " " since I am on windows but still no luck).

I known I sound strange but I am pretty sure the code I posted was working today but now it seems to not work anymore I really don't known what to say...weird.
Title: Re: Almost complete script needs some fixing
Post by: Hayo Baan on July 24, 2014, 04:51:24 PM
Alyssa,

Oops, sorry, forgot to adjust the second pair of quotes, but for you this should work:
exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%A]" -p "${file:filecreatedate}"
Of course provided you feed it a filename. Output should be in the terminal window. Oh, but perhaps you misunderstood me that this is the command to use to change the files. This one only prints out the text for testing and does not change the files at all. For that you'll need your own code minus the %% and perhaps with the escaped [ and ] like I said.

Cheers,
Hayo
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 24, 2014, 05:30:05 PM
I am not too sure if I did this right, but here's the result:

(https://lh3.googleusercontent.com/01dABebQk5C9N3bng4PK9G3zcmDyPGZ3BQM8fQ69zdbk=w676-h341-no)
Title: Re: Almost complete script needs some fixing
Post by: Phil Harvey on July 24, 2014, 07:03:19 PM
Your initial command looks correct except for the trailing "%%".  I don't know what type of script you are talking about, but apparently not a .BAT file because you didn't need to double all the other % characters.

It looks like %A just doesn't work in Windows.  These codes are system dependent, so that doesn't surprise me too much.  Does %a (abbreviated weekday) work?

As for the "Can't locate PAR.pm" problem, see this post (https://exiftool.org/forum/index.php/topic,2630.msg11627.html#msg11627) for a solution.

- Phil
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 24, 2014, 08:13:40 PM
Well after some tries I realized that %A just doesn't work while %a does (Im using Windows 8.1). So far with this code:

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" "-exif:XPComment<file:filecreatedate" -P

I get
24/07/2014 Custom Text 15:40:52[thu]

But there's still a couple problems, every time I use this code it creates a backup file (.jpg_original) I don't know why.
Also it isn't possible to get [Thursday] instead of [thu] ?
Title: Re: Almost complete script needs some fixing
Post by: ryerman on July 24, 2014, 09:33:21 PM
Here it is in Windows 7.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>exiftool -p $file:filecreatedate F:\AnyFile.jpg
2014:07:24 21:11:04-04:00

C:\Windows\system32>exiftool -d "%d/%m/%Y Custom Text %H:%M:%S[%A]" -p $file:filecreatedate F:\AnyFile.jpg
24/07/2014 Custom Text 21:11:04[Thursday]

C:\Windows\system32>


I have no knowledge about how or why it works.
You could try playing around with the system time and date format (Control Panel > Region and Language).

To delete the backup file, add -overwrite_original to the command
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 24, 2014, 10:12:11 PM
I have tried with compatibility's function, set on Win 7, and still nothing, the "%A" won't work, only the "%a".

This is the error:
(https://lh6.googleusercontent.com/-uOZqKyVWOuE/U9G9ilYxjfI/AAAAAAAB2fw/ezLV-8YznwE/w663-h333-no/Senza+titolo+-+1.jpg)
Title: Re: Almost complete script needs some fixing
Post by: Hayo Baan on July 25, 2014, 03:34:23 AM
Hi Alyssa,

I don't know where the malformed UTF-8 errors come from. Have you perhaps written to the comment field using other software than exiftool? Anyway, back to your original problem of getting e.g. Thursday in the comment field. It is possible, even if %A doesn't work, it's going to be quite a hack to get it done though...

exiftool -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -p "${file:filecreatedate;s/\[mon\]/[Monday]/;s/\[tue\]/[Tuesday]/;s/\[wed\]/[Wednesday]/;s/\[thu\]/[Thursday]/;s/\[fri\]/[Friday]/;s/\[sat\]/[Saturday]/;s/\[sun\]/[Sunday]/}"

Basically we substitute the [...] sequences with their full name representatives. The first [] is escaped as these are special characters in a pattern. Note that on my system (Mac), %a gives me the short weekdays starting with a capital letter...
Seems we can not guarantee any consistency across platforms (and not even within a platform as Windows does and does not support %A properly).

Hope this helps,
Hayo
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 25, 2014, 07:29:09 AM
No I haven't written the files with other programs ( I downloaded a couple of random of images from internet just for this test).
But could you tell me how I can integrate your code in my original?
I've tried something like this

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -p "-exif:XPComment<${file:filecreatedate;s/\[mon\]/[Monday]/;s/\[tue\]/[Tuesday]/;s/\[wed\]/[Wednesday]/;s/\[thu\]/[Thursday]/;s/\[fri\]/[Friday]/;s/\[sat\]/[Saturday]/;s/\[sun\]/[Sunday]/}"

But its not working, I guess I did something wrong again...
Title: Re: Almost complete script needs some fixing
Post by: Hayo Baan on July 25, 2014, 07:43:14 AM
Quote from: Alyssa on July 25, 2014, 07:29:09 AM
No I haven't written the files with other programs ( I downloaded a couple of random of images from internet just for this test).
But could you tell me how I can integrate your code in my original?
Well, then it looks like the files from the internet have an invalid XPComment...

Quote from: Alyssa on July 25, 2014, 07:29:09 AM
I've tried something like this

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -p "-exif:XPComment<${file:filecreatedate;s/\[mon\]/[Monday]/;s/\[tue\]/[Tuesday]/;s/\[wed\]/[Wednesday]/;s/\[thu\]/[Thursday]/;s/\[fri\]/[Friday]/;s/\[sat\]/[Saturday]/;s/\[sun\]/[Sunday]/}"

But its not working, I guess I did something wrong again...

Yep, you left the -p (lowercase!) for printing the output in your statement. If you change that to your own -P (uppercase!) to preserve the timestamps you'll be fine. And if you then also do not want any _original files, add in -overwrite_original as well. That should fix it :D

Cheers,
Hayo
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 25, 2014, 08:00:16 AM
It works now, but it still create the jpg_original file for some reason, I have tried to put the  -overwrite_original at the end, in the middle, at the start of the code, it still create the original.

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_original
and
C:\exiftool.exe -d  -overwrite_original "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}"
or (this below doesn't even work "no file specified")
C:\exiftool.exe -d  "%d/%m/%Y Custom Text %H:%M:%S[%a]" -overwrite_original -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}"

I think I've tried all possible locations
Title: Re: Almost complete script needs some fixing
Post by: Hayo Baan on July 25, 2014, 09:14:23 AM
Alyssa,

I have no idea why the first and last versions didn't work, I copied your first line (just changed " for ') and apart from the substitutions not working due to my language being set to English instead of Italian, it worked fine and did not create a _original file. Could it be that those _original files where already present?

(the second line does not work as now the argument to the -d option has become -overwrite_original which is not a valid format specification ;))

Cheers,
Hayo
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 25, 2014, 10:40:41 AM
Its a strange, the code works but it still create a jpg_original for me, maybe its an issue with Windows 8?

Edit:
It seems like I discovered the reason behind this, the code its just too long to put it in a link (it gets cutted near the end)

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_o

So I guess I should use a .bat file instead?
Title: Re: Almost complete script needs some fixing
Post by: Phil Harvey on July 25, 2014, 10:44:11 AM
Are you sure the "_original" file isn't from an earlier command?  It should never create this backup if -overwrite_original is used.  Windows 8 shouldn't make a difference.

- Phil
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 25, 2014, 01:02:49 PM
Yes in noticed after that it wasn't added because the overall line exceeded the limit of the maximum number of characters in a shortcut.

Original:
C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_original

After:
C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_o

So I was looking to do things in another way, using a .bat file...so I tried to write the exact line into a txt file plus adding a directory's path and save it as .bat
Its as it follows

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_original C:\Users\Random\Desktop\Test 2\

Also tried by specify the extension

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_original C:\Users\Random\Desktop\Test 2\*.jpg

Other random try

C:\exiftool.exe -d "%d/%m/%Y Custom Text %H:%M:%S[%a]" -P "-exif:XPComment<${file:filecreatedate;s/\[lun\]/[Monday]/;s/\[mar\]/[Tuesday]/;s/\[mer\]/[Wednesday]/;s/\[gio\]/[Thursday]/;s/\[ven\]/[Friday]/;s/\[sab\]/[Saturday]/;s/\[dom\]/[Sunday]/}" -overwrite_original C:\Users\Random\Desktop\Test 2\*.*

But Its not working, still trying to it figure out as I am writing this.
Title: Re: Almost complete script needs some fixing
Post by: Phil Harvey on July 25, 2014, 01:20:41 PM
Hi Alyssa,

You need to double all "%" characters in a .BAT file, as I mentioned earlier.

- Phil
Title: Re: Almost complete script needs some fixing
Post by: Alyssa on July 25, 2014, 01:24:13 PM
Yeah I just realized the error. Thanks everyone for the help, now it should be perfect. Cheers.

Edit:
Sorry,one little last thing,I noticed exiftool don't like some characters like ì (used in Lunedì, italian for Monday), how I can make it write it?

I have tried with -charset Latin but it writes ý instead of ì

Edit #2:
I solved with -E command and &igrave; for "ì"