Hi Guys,
Here is my problem.
I have around 30 folders containing around 900 odd PDFs each. (single pages from a book)
I have to Merge them using acrobat into chapters (groups of 30 odd)
They have been supplied to me with silly filenames which doesn’t sort when I add them into acrobat.
Is there a script for change the part of a name. I need the “.p1.pdf to .p9.pdf” to be “.p01.pdf to .p09.pdf”
So when I bring them in acrobat they are arlready sorted into the correct order
All the ones I have found are for deleting parts of filenames or only changing extensions etc. I could’nt find any which adds the specific charator???
Something like this will do the padding (I am assuming you know how to get the names and set them)
-- given a list of names to be corrected...
set tNames to {"121517_P001_051.p1.pdf", "121517_P001_051.p2.pdf,121517_P001_051.p3.pdf", "121517_P001_051.p4.pdf.121517_P001_051.p5.pdf", "121517_P001_051.p6.pdf", "121517_P001_051.p7.pdf.121517_P001_051.p8.pdf", "121517_P001_051.p9.pdf", "121517_P001_051.p10.pdf", "121517_P001_051.p11.pdf"}
set tid to AppleScript's text item delimiters
repeat with aName in tNames
if aName ends with ".pdf" then
set AppleScript's text item delimiters to ".p"
set TI to text items of aName
set item 2 of TI to pad(item 2 of TI, 2)
set contents of aName to TI as string
end if
end repeat
set AppleScript's text item delimiters to tid
-- results in a new list, same name:
tNames --> {"121517_P001_051.p01.pdf", "121517_P001_051.p02.pdf,121517_P001_051.p3.pdf", "121517_P001_051.p04.pdf.121517_P001_051.p5.pdf", "121517_P001_051.p06.pdf", "121517_P001_051.p07.pdf.121517_P001_051.p8.pdf", "121517_P001_051.p09.pdf", "121517_P001_051.p10.pdf", "121517_P001_051.p11.pdf"}
on pad(num, howLong) -- how long decides how many digits in the number following ".p".
--set thisNum to num as text
set c to count num
repeat howLong - c times
set num to "0" & num
end repeat
return num
end pad
Thanks Adam,
I don’t know how to get a list and apply the names to the files.
Most of the Applesscripts have been involved in have concerned a specific file, or a file of my choosing, so I haven’t had the need to be so broad in my approach until now.
This has worked so welll it’s saved me soo long renaming files manually.
Now I know how to get a list and apply it, I’ll be able do so many other things…
I know I don’t post much here, But I’m learning heaps so one day i should be able to help others.
Thanks so much guys…
For anyone else who need this, here it is…
tell application "Finder"
set theFiles to every file of (choose folder)
set tNames to name of every file of (choose folder)
end tell
set tid to AppleScript's text item delimiters
repeat with aName in tNames
if aName ends with ".pdf" then
set AppleScript's text item delimiters to ".p"
set TI to text items of aName
set item 2 of TI to pad(item 2 of TI, 2)
set contents of aName to TI as string
end if
end repeat
set AppleScript's text item delimiters to tid
-- results in a new list, same name:
tNames
on pad(num, howLong) -- how long decides how many digits in the number following ".p".
--set thisNum to num as text
set c to count num
repeat howLong - c times
set num to "0" & num
end repeat
return num
end pad
tell application "Finder"
repeat with i from 1 to count tNames
set name of (item i of theFiles) to (item i of tNames)
end repeat
end tell
You should make a sticky which has a heap of really really basic generic stuff for people like me who just need something quick and easy…
It would save people like me having to ask really easy questions
e.g.
Why do people always set variable names?
How to get a list of files in a folder
How to change the name of them
repeat loops
Little snippets of self contaned code which people can quickly copy and paste into something they have to make work.
On second thoughts maybe that’s too hard to narrow down…
Marcus, I used to use a script back in version 6 of Acrobat that would create multi page docs from single/multi page PDF’s using numbers in the file name to sort the order and the text to create bookmarks. However in version 7 Acrobat included a very nice feature: menubar/file/create pdf/from multiple files. this creates binders of sections (your chapters) which you can rebind into larger binders bookmarking is in there too and also just drag and drop the stacking for the sort order you want.
Hi Mark,
Thanks how I’ve been combining them, However, when you have files which are called e.g
Filename1.pdf
Filename2.pdf
Filename3.pdf
Filename4.pdf
Filename5.pdf
Filename6.pdf
Filename7.pdf
Filename8.pdf
Filename9.pdf
Filename10.pdf
Filename11.pdf
When they are place brought into acrobat, they reorder to be:
I can’t be bothered typing all the filenames, but when you have 900 plus moving pages becomes very time consuming.
That’s why I needed a solution which will rename them to have a 0 in front of the single digits so they come into Acrobat in order, that way I don’t have sit ther for ever reshuffling then around.
Sorry if the filename above don’t make sence. Try it, you will see what I mean.
I don’t want to stop anyone here from using or learning AppleScript. That said, I’ve used File List to rename files ever since I found it. With the “Use Finder selection on startup” option, you can just select files in the Finder, open File List, choose “Number sequentially”, check “Use common prefix”, and then let File List handle the rest.