Need help: creating image copy for each keyword into subfolder

Started by chainlover, May 12, 2017, 07:08:08 PM

Previous topic - Next topic

chainlover

Hi everyone. I have problem with making my idea possible

So, I have several images. I want each image to be copied into subfolder for <b>each</b> of its keywords. In case the folder doesn't yet exist, it is created

example:
1.jpg
exiftool 1.jpg -Keywords
keyword1, keyword2, keyword3, keyword4...,keywordn

now what I wanted to do was to run the following in bash terminal:
exiftool "-directory<Keywords" *.jpg

however that's not exactly what I want to do: there is attempt to create only one folder. of course it fails... As the name is too long:
<b>Error creating directory keyword1, keyword2, keyword3, keyword4...,keywordn
    0 image files updated
    1 files weren't updated due to errors

</b>

can anyone help me with further actions? I seem to be stuck

Phil Harvey

ExifTool will only create a single copy of a file, but with multiple commands you can do what you want:

exiftool -listItem 0 "-directory<keywords" -ext jpg .
exiftool -listItem 1 "-directory<keywords" -ext jpg .
exiftool -listItem 2 "-directory<keywords" -ext jpg .
exiftool -listItem 3 "-directory<keywords" -ext jpg .
exiftool -listItem 4 "-directory<keywords" -ext jpg .
exiftool -listItem 5 "-directory<keywords" -ext jpg .
...


But instead of duplicating the file so many times, why not make hard links?:

exiftool -listItem 0 "-hardlink<$keywords/%f.%e" -ext jpg .
exiftool -listItem 1 "-hardlink<$keywords/%f.%e" -ext jpg .
...


Unless you want to edit the files separately afterwards, you could do this to save a lot of disk space.

- 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

I was thinking use -api "Filter=" and -p to create a command, redirect the output to a file and run it as a batch.  Something like
exiftool -q -if "$keywords" -p "exiftool $keywords -common_args $filename#" -api "filter=$_=' -o . -directory=/target/dir/'.$_.' -execute '" -sep "" FileOrDir >temp.bat

Obviously, this is windows version and need some quote changes for bash.  Also, an extra execute at the end, but that would just list the metadata and not actually do anything. 

Example

C:\>exiftool -keywords X:\!temp\Test*.jpg
======== X:/!temp/Test.jpg
Keywords                        : technics, dot, work, shop, blank, space, under, space, now, more
======== X:/!temp/Test3.jpg
Keywords                        : A, B, C, D
======== X:/!temp/Test4.jpg
Keywords                        : ocean, HiThere
======== X:/!temp/Test5.jpg
Keywords                        : Keyword 1, Keyword 2, keyword 6
======== X:/!temp/test6.jpg
======== X:/!temp/Testa.jpg
======== X:/!temp/TestGrayscale.jpg
Keywords                        : ocean, HiThere
    7 image files read

C:\>exiftool -q -if "$keywords" -p "exiftool $keywords  -common_args $filename#" -api "filter=$_=' -o . -directory=\"/target/dir/'.$_.'\" -execute '" -sep "" X:\!temp\Test*.jpg
exiftool  -o . -directory="/target/dir/technics" -execute  -o . -directory="/target/dir/dot" -execute  -o . -directory="/target/dir/work" -execute  -o . -directory="/target/dir/shop" -execute  -o . -directory="/target/dir/blank" -execute  -o . -directory="/target/dir/space" -execute  -o . -directory="/target/dir/under" -execute  -o . -directory="/target/dir/space" -execute  -o . -directory="/target/dir/now" -execute  -o . -directory="/target/dir/more" -execute   -common_args Test.jpg
exiftool  -o . -directory="/target/dir/A" -execute  -o . -directory="/target/dir/B" -execute  -o . -directory="/target/dir/C" -execute  -o . -directory="/target/dir/D" -execute   -common_args Test3.jpg
exiftool  -o . -directory="/target/dir/ocean" -execute  -o . -directory="/target/dir/HiThere" -execute   -common_args Test4.jpg
exiftool  -o . -directory="/target/dir/Keyword 1" -execute  -o . -directory="/target/dir/Keyword 2" -execute  -o . -directory="/target/dir/keyword 6" -execute   -common_args Test5.jpg
exiftool  -o . -directory="/target/dir/ocean" -execute  -o . -directory="/target/dir/HiThere" -execute   -common_args TestGrayscale.jpg


Still would need some tweaks for bash.
* 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).

chainlover

Quote from: Phil Harvey on May 12, 2017, 11:01:40 PM
ExifTool will only create a single copy of a file, but with multiple commands you can do what you want:

exiftool -listItem 0 "-directory<keywords" -ext jpg .
exiftool -listItem 1 "-directory<keywords" -ext jpg .
exiftool -listItem 2 "-directory<keywords" -ext jpg .
exiftool -listItem 3 "-directory<keywords" -ext jpg .
exiftool -listItem 4 "-directory<keywords" -ext jpg .
exiftool -listItem 5 "-directory<keywords" -ext jpg .
...


But instead of duplicating the file so many times, why not make hard links?:

exiftool -listItem 0 "-hardlink<$keywords/%f.%e" -ext jpg .
exiftool -listItem 1 "-hardlink<$keywords/%f.%e" -ext jpg .
...


Unless you want to edit the files separately afterwards, you could do this to save a lot of disk space.

- Phil
Thanks so much Phil, that's exactly what I was looking for. Perfect

However is there any way to actually copy files, not move them? As exiftool will move all files wit first command and I will not have anything to do with second command

I know it requires a lot of space but this is not a large images directory, and it's more for test and learning purposes.

Phil Harvey

Right.  To copy the files I should have added -o . to the commands [edit: when writing Directory].

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