Renaming File Based on Data Inside the File

Advanced Renamer forum
#1 : 17/10-18 17:53
Audrey Young
Audrey Young
Posts: 1
I have 500 single page PDFs in one directory. I need to rename the file based on data within the file - a specific row in the file.

Example of the data is :
Company Name
Date
Fac### StateCityName

I want the filename to be Fac### StateCityName.pdf

Is this possible??


17/10-18 17:53
#2 : 18/10-18 21:52
David Lee
David Lee
Posts: 43
Reply to #1:

Hi Audrey

I thought that this should be a simple matter of using the Advanced Tag <File Line> in the New Name method - but this does not appear to work with PDF files.

I have found a procedure that works with PDF files I have on my desktop.

This requires the use of two methods, working together in series: First of all use the Advanced Tag <File Content> in the New Name method and select a sufficiently large block of data to be sure of including the whole line you want to use. As a test, I have used <File content:0:1024>.

Now open a second method to work on the output of the first - Use the Replace method and tick "Use regular expressions". The expression to use is: ((.*\n){4})(.*\n)((.*\n)*.*) and "Replace with" \3

Note that the number in braces - {4} in my example - is the number of lines to skip before the line you want to use, so you will need to change it as appropriate.

The RegEx is in the form of three sub-patterns. The first ((.*\n){4}) matches 4 blocks of characters each ending in a newline. The second (.*\n) matches the next line - ie the one you want to use. Finally ((.*\n)*.*) matches all the remaining lines ending in newline plus whatever is left over at the end of the block of characters.

The "Replace with expression" - \3 - selects which of the sub-patterns you want to use. This is where the behaviour is unexpected as you would expect that you would need to select the second sub-pattern - \2 - but this repeats the final line in the first block. If anyone else can explain this behaviour I would be very grateful.

Anyway this solution works for me so give it a try and let us know if it works.


18/10-18 21:52