Lists of image paths to be exiftooled through a cmd file

Started by sylf, January 23, 2022, 10:30:24 AM

Previous topic - Next topic

sylf

Hello.
I have several txt files in different subdirectories. These txt files include image paths like these:

U:\collections\dir1\dir3\file1.jpg
U:\collections\dir1\dir3\file2.jpg
U:\collections\dir1\dir3\dir4\file3.jpg

As an output, I want an xml file per image in the same directory where each corresponding txt file is located.
In my cmd code, I tried:

for /R U:\collections\ %%f in (*.txt) do (
    set txtfile=%%f
    set folder=[here I want the path of the txtfile where the the image paths are listed]
    perl C:\Windows\exiftool\exiftool.pl -@ %txtfile% -X -w %folder%\%%f.xml
)

It does not work.
Would be nice to get help :)
Sylvain

StarGeek

In what way does it not work?  What is the output from running that script?
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sylf

Output is :

Error creating U:\collections\dir1\dir3\file1U:\collections\dir1\dir3U:\collections\dir1\dir3\file1.txt.xml
Error creating U:\collections\dir1\dir3\file2U:\collections\dir1\dir3U:\collections\dir1\dir3\file2.txt.xml
etc.
0 image files read
17 files could not be read
0 output files created

StarGeek

This is a batch problem, in which I can't be much help with.  But the problem is that you're combining variables that already include a path.  That's why your output shows multiple paths when trying to write.

Remember, %%f contains "U:\collections\dir1\dir3\file1.jpg", not "file1.jpg".  %folder% contains the path you want to write to.  You're then trying to write %folder%\%%f, which results in the two paths being combined.  Then there's another full path getting added in there somehow.

You need to edit your batch variables to only include the parts needed to make your target path.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sylf

You are right, this is a batch problem.
Thanks for the tips, StarGeek.
Any other suggestion from anyone welcome (although it is a batch problem).
S

StarGeek

Take a look at this Microsoft page.  It appears to be down at this moment, but there's a backup on Archive.org.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sylf

Thanks for the reference, StarGeek, but I did not guess what I could manage with it.
With the new code :
for /R U:\collections\ %%f in (*.txt) do (
    set txtfile=%%f
    echo %txtfile%
    set fileNameWithoutExt=%%~nf
    echo %fileNameWithoutExt%
    set fileNameWithExt=%%~nf%%~xf
    echo %fileNameWithExt%
    set pathWithoutFileName=%%~df%%~pf
    echo %pathWithoutFileName%
    perl C:\Windows\exiftool\exiftool.pl -@ %txtfile% -X -w %pathWithoutFileName%%%g.xml
)

... it seems that I am not too far from solution, but I get this error :
Output file U:\collections\dir1\dir3\.xml already exists for U:\collections\dir1\dir3\file1
So, exiftool cannot build the xml filename from the line in the txt source file as it can when there is no for-loop.

StarGeek

You have %%g as the variable for the filename.  And since it isn't declared anywhere in your script, it's empty.  Which means you're creating a file called .xml (nothing before the dot) for every file in the list.  And once you've created the first one, exiftool won't overwrite it.

Try using this (I think)
-w %pathWithoutFileName%"%%f.xml"
The %%f in the quotes should be passed to exiftool as exactly that.  Exiftool will read it as one of it's own percent tokens (see -w (-TextOut) option) and replace it with the base filename.

Or you could use the variable you created
-w %pathWithoutFileName%%fileNameWithoutExt%.xml
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sylf

Many thanks for your further suggestions, Stargeek.
I tried several options from them, with no satisfying result unfortunately.
I will try something completely different to get what I need.
... I am however wondering whether I would have had more chances with a perl script (what I am not able to do at the time being).

sylf

I am finally continuying my trials.
Following command works :
S:\Data\perl>C:\Windows\exiftool\exiftool.pl "U:\collections\ACK.tif" -X > "U:\collections\test\ack.xml"
Following command produces an error :
S:\Data\perl>C:\Windows\exiftool\exiftool.pl "U:\collections\ACK.tif" -X -w "U:\collections\test\ack.xml"
Error creating U:/collections/ACKU:/collections/test/ack.xml
    1 files could not be read
    0 output files created

In the first command, I use ">" to get my xml file. In the second, I use Exiftool option "-w".
Thanks in advance if you have any explanation.

Phil Harvey

Could this be a permissions problem?  But I don't understand how cmd.exe would have permission while perl.exe doesn't.

- 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 ($).

StarGeek

What kind of drive is U: ?  Your command says to write to U:\collections\test but for some reason exiftool thinks it's U:/collections/ACKU:/collections/test, with a second colon included.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sylf

I would not bet that this is a permission- to-U:-problem.
If it was the case, would I be able to run the ">"-solution to get my output?
Would I also be able to run this :
C:\Windows\exiftool\exiftool.pl -@ U:\collections\list_of_image_paths_on_U.txt -X -w %d%f.xml
with success?
U: is a "server storage space", sorry I am not able to say something more specific.


Phil Harvey

@StarGeek: You're more observant than I.  Yes.  Something very odd is going on with the directory name on U:.  The key may be to figure out where "ACKU:" is coming from.

- 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 ($).