ExifTool Forum

ExifTool => Newbies => Topic started by: Kinnie2014 on February 22, 2017, 10:33:43 AM

Title: tag pagecount into filename of txt file
Post by: Kinnie2014 on February 22, 2017, 10:33:43 AM
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
Title: Re: tag pagecount into filename of txt file
Post by: Phil Harvey on February 22, 2017, 10:43:10 AM
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
Title: Re: tag pagecount into filename of txt file
Post by: Kinnie2014 on February 22, 2017, 01:08:13 PM
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.
Title: Re: tag pagecount into filename of txt file
Post by: Phil Harvey on February 22, 2017, 02:01:20 PM
No, sorry.  For safety reasons ExifTool will never overwrite a file when renaming.

- Phil
Title: Re: tag pagecount into filename of txt file
Post by: Kinnie2014 on February 23, 2017, 03:27:09 AM
Ok thank you.