Almost complete script needs some fixing

Started by Alyssa, July 24, 2014, 10:36:02 AM

Previous topic - Next topic

Alyssa

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

Hayo Baan

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
Hayo Baan – Photography
Web: www.hayobaan.nl

Alyssa

#2
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.

Hayo Baan

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
Hayo Baan – Photography
Web: www.hayobaan.nl

Alyssa

I am not too sure if I did this right, but here's the result:


Phil Harvey

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 for a solution.

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

Alyssa

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] ?

ryerman

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
Windows 10 Home 64 bit, Exiftool v12.61

Alyssa

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:

Hayo Baan

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
Hayo Baan – Photography
Web: www.hayobaan.nl

Alyssa

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...

Hayo Baan

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
Hayo Baan – Photography
Web: www.hayobaan.nl

Alyssa

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

Hayo Baan

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
Hayo Baan – Photography
Web: www.hayobaan.nl

Alyssa

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?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Alyssa

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.

Phil Harvey

Hi Alyssa,

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

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

Alyssa

#18
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 "ì"