Here's a similar tool which could easily be altered to suit your needs.
RenamePDF - Rename PDF files to the internal name found in the /Title tag.
Skrommel
;RenamePDF.ahk
; Rename PDF files to the internal name found in the /Title tag
;Skrommel @ 2008
recurse=0 ;change to 1 to recurse subfolders
#SingleInstance,Force
#NoEnv
SetBatchLines,-1
applicationname=RenamePDF
FileSelectFolder,source,%A_ScriptDir%,3,%applicationname%`nSelect where to look for PDF-files to rename
needle:="/Title(" ;the text to look for
hexneedle:=Asc2Hex(needle)
;Stolen from Lazlo and others at http://www.autohotkey.com/forum/topic25925-30.html
;;;;; Initialization of 2 machine code functions, for setting input and showing results
MCode(Hex2Bin,"568b74240c8a164684d2743b578b7c240c538ac2c0e806b109f6e98ac802cac0e10"
. "4880f8a164684d2741a8ac2c0e806b309f6eb80e20f02c20ac188078a16474684d275cd5b5f5ec3")
MCode(Bin2Hex,"8B54240C85D2568B7424087E3A53578B7C24148A07478AC8C0E90480F9090F97C3F"
. "6DB80E30702D980C330240F881E463C090F97C1F6D980E10702C880C130880E464A75CE5F5BC606005EC3")
Loop,%source%\*.pdf,0,%recurse%
{
filename:=A_LoopFileLongPath
BinRead(filename,F) ; binary haystack
Hex2Bin(H,hexneedle) ; binary search string
QtBuf(Q,QLen,H,20) ; Make RegEx quote
foundpos:=RegExMatch(F,Q)-1
If foundpos<0
Continue
BinRead(filename,F,255,foundpos+StrLen(needle))
Loop,Parse,F,`n
{
StringTrimRight,foundtext,A_LoopField,1
StringReplace,foundtext,foundtext,\,,All
SplitPath,filename,name,dir,ext,name_no_ext,drive
MsgBox,4,%applicationname%,Rename`n %filename%`nto`n %dir%\%foundtext%.pdf
IfMsgBox,Yes
{
newname:=foundtext
Loop
{
IfNotExist,%dir%\%newname%.pdf
Break
InputBox,newname,%applicationname%,File %foundtext% exists`nRename,,,,,,,,%newname%
If ErrorLevel=1
Break
}
FileMove,%filename%,%dir%\%newname%.pdf
Break
}
}
}
Return
Asc2Hex(needle)
{
hexneedle=
SetFormat,Integer,Hex
Loop,Parse,needle
{
char:=Asc(A_LoopField)
StringMid,char,char,3,2
hexneedle:=hexneedle . char
}
SetFormat,Integer,Dec
Return,%hexneedle%
}
QtBuf(ByRef Q, ByRef QLen, ByRef B, BLen) { ; replace each \E with \E\E\Q, enclose in \E..\Q
RegExReplace(B, "\\E","",n)
QLen := BLen+4*n+4
VarSetCapacity(Q,QLen,1)
If (n > 0) {
VarSetCapacity(C,QLen-4,1)
C := RegExReplace(B, "\\E", "\E\E\Q") ; AHK copies result over \0's
Q := RegExReplace(C, ".*", "\Q$0\E") ; enclose result in \E..\Q
} Else
Q := RegExReplace(B, ".*", "\Q$0\E")
}
BinRead(file, ByRef data, n=0, offset=0) { ; n = #bytes/all; neg offset from end
h := DllCall("CreateFile",Str,file, UInt,0x80000000, UInt,3, UInt,0, UInt,3, UInt,0, UInt,0)
m := 2*(offset < 0) ; offset >= 0 : m = 0; offset < 0: m = 2
DllCall("SetFilePointerEx",UInt,h, Int64,offset, UIntP,U, Int,m)
m := DllCall("GetFileSize",UInt,h, Int64P,r)
If n not between 1 and %m%
n = %m%
VarSetCapacity(data, n, 1)
DllCall("ReadFile",UInt,h, UInt,&data, UInt,n, UIntP,r, UInt,0)
DllCall("CloseHandle", UInt,h)
Return r
}
Bin2Hex(addr,len) { ; convert binary data at addr to hex stream
Local hex
VarSetCapacity(hex,2*len+1)
Dllcall(&Bin2Hex, "uint",&hex, "uint",addr, "uint",len, "cdecl")
VarSetCapacity(hex,-1) ; update StrLen
Return hex
}
Hex2Bin(ByRef buf, hex) { ; convert hex stream to binary data
Global Hex2Bin
VarSetCapacity(buf,(StrLen(hex)+1)//2,1)
Dllcall(&Hex2Bin, "uint",&buf, "uint",&hex, "cdecl")
}
MCode(ByRef code, hex) { ; allocate memory and write Machine Code there
VarSetCapacity(code,StrLen(hex)//2)
Loop % StrLen(hex)//2
NumPut("0x" . SubStr(hex,2*A_Index-1,2), code, A_Index-1, "Char")
}