tag pagecount into filename of txt file

Started by Kinnie2014, February 22, 2017, 10:33:43 AM

Previous topic - Next topic

Kinnie2014

Hello,

I try to get the pagecount of a pdf-file into the filename of a txt-file.

Until now, I got this: With 

exiftool -pagecount glass.pdf > out.txt

I get a txt-file named out.txt and in there I have one line with the contents of the tag pagecount in glass.pdf:

"Page Count                      : 11"

I also got this: With

exiftool "-filename<%f_${pagecount}.%e" glass.pdf

I get the pdf file with the added page number in the file name. In this case glass.pdf contains 11 pages, so I get

"glass.pdf"  becomes to  "glass_11.pdf"

But what I want, is a text file with the page number of the pdf in its filename. So that I take the tag pagecount from "glass.pdf" and then write an output file with the name "out_11.txt"

I tried several things but haven't found the right solution. Is it possible with exiftool?

Thanks in advance

Phil Harvey

The exiftool app isn't really designed for this, but you can achieve what you want with a bit of pain:

exiftool -w txt -ext pdf -execute -srcfile %d%f.txt -tagsfromfile %d%f.pdf '-filename<%f_${pagecount}.txt' -common_args DIR

This command generates the .txt files then renames them based on the PageCount in the associated .pdf file.

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

Kinnie2014

Dear Phil,

thanks, this pain works great.

I now use:

exiftool -pagecount -w! txt -ext pdf -execute -srcfile %d%f.txt -tagsfromfile %d%f.pdf "-filename<%f_${pagecount}.txt" -common_args glass.pdf

and I get a "glass_11.txt" file.

Now when I execute this again, the "glass_11.txt" already exists and can't be overwritten, but the glass.txt output file can be created again and again (thanks to w!). So the "glass.txt" can't be renamed again to "glass_11.txt".

Is there any clue for this? I experimented with the -overwrite_original flag, but haven't found a solution.

Phil Harvey

No, sorry.  For safety reasons ExifTool will never overwrite a file when renaming.

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