Is it possible, in Windows, to use exiftool to assign an environment variable to an Exif value of a file? (For example, the duration of a video?)
You should be able to do this using the Windows command to set an environment variable and the backtick operator. I don't know what that looks like in Windows, but in Unix it could be something like:
set myvariable=`exiftool -duration -s3 FILE`
- Phil
For CMD, you would use % signs to indicate a variable
C:\>exiftool -P -overwrite_original -description=%ProgramData% y:\!temp\Test4.jpg
1 image files updated
C:\>exiftool -G1 -a -s -description y:\!temp\Test4.jpg
[XMP-dc] Description : C:\ProgramData
This doesn't work in PowerShell because of course it doesn't :(
Note the highlighting that tells you what is considered a string and what is a variable.
(https://i.imgur.com/VxAMHL4.png)
So I went the wrong way it seems? I thought you wanted to set an environment variable based on EXIF from a file.
- Phil
Now I'm not sure. You may be correct.
Going your way, the backtick doesn't work on CMD.
I found this StackOverflow answer (https://stackoverflow.com/questions/55225213/) for assigning the output from a command to an ENV variable.
Quote from: Phil Harvey on October 28, 2022, 03:10:51 PMSo I went the wrong way it seems? I thought you wanted to set an environment variable based on EXIF from a file.
- Phil
You might have momentarily confused StarGeek with me (the OP). :)
Phil, you are correct in what you thought.
My Windows console skills are pretty solid (but not perfect), and AFAIK the Linux backtick operator trick won't work in Windows.
Using the Windows console (I don't use PowerShell often enough to remember all its ins-and-outs), the only trick I know is the `FOR` loop hack that StarGeek graciously linked to. Of course, that hack is ugly and hard to read, but if its the only Windows console technique available, I'll test it to see if it works with exiftool.
I could launch PowerShell for that one command, but PowerShell is rather lethargic when being called for a single command. When that command is in a loop, it's painfully slow.
Yet another reason to completely switch everything to Linux! 8)
Quote from: ifihadahammer on October 29, 2022, 04:55:10 AMYou might have momentarily confused StarGeek with me (the OP). :)
No. He sometimes reads a question one way while I read it a different way, then we both come up with a solution to our specific ways and then confuse each other with what the original poster wanted. Usually it's me jumping to the wrong conclusion (as in this case) and me re-reading the question.
QuoteUsing the Windows console (I don't use PowerShell often enough to remember all its ins-and-outs),
PS is my bane due to all its peculiarities that are unlike any other shell. Even something so simple as the exiftool's json option,
-j=file.json, doesn't work because PS, for some reason, doesn't think the extension is part of the command and that disappears into the ether.
Quotethe only trick I know is the `FOR` loop hack that StarGeek graciously linked to. Of course, that hack is ugly and hard to read, but if its the only Windows console technique available, I'll test it to see if it works with exiftool.
It does work, there are a few examples on this forum someplace. But of course, looping exiftool is slow (see Common Mistake #3 (https://exiftool.org/mistakes.html#M3)) so if you have a lot of files, it's best if you could read all the files/dirs at once and then parse the output.
QuoteYet another reason to completely switch everything to Linux! 8)
There's always the Windows Subsystem for Linux (WSL) (https://learn.microsoft.com/en-us/windows/wsl/about). I still haven't figured it out, but using exiftool through that would solve a lot of Windows specific problems. Though I don't know if Windows executables work work there.
I have WSL installed because it's real easy to install through Chocolatey, Windows Subsystem for Linux (Install) 1.0.1 (https://community.chocolatey.org/packages/wsl), and then you can pick your flavor of linux, such as Ubuntu LTS for WSL (https://community.chocolatey.org/packages/wsl-ubuntu-1804/18.04.1.020181923).