Skip to main content
AidanCable
Participant
December 17, 2024
Answered

Action that copies file to folder based on page count

  • December 17, 2024
  • 1 reply
  • 741 views

Hi all! - got a little scenario I need help solving, hoping some of you clever minds can help me!

I have a bundle of files that will be delivered to me each week, these will be varying in page count from:
34, 36, 38 & 40 pages (possibly more havent been told yet).

I need these split into seperate folders based on the page count... Ideally I don't want to be doing this manually, opening each oneindividually, checking page count, then dragging over to a folder...

I have an action set up for these already as pages need rotating, flattening ect, so my ideal outcome is to have some javascript that will execute as part of this workflow inside this action. It would count the pages, and move to a folder located on my mac. 

Not sure if this is possible, couldn't find much online! Thanks for the help in advanced!

This topic has been closed for replies.
Correct answer PDF Automation Station

Sorry, I forgot the quotes (now corrected).  It should be:

this.saveAs("/Volumes/ClientFolder/Client1/TestFolder/" +"Page_"+ this.numPages+ "/"+this.documentFileName);

1 reply

PDF Automation Station
Community Expert
Community Expert
December 17, 2024

In this example, assume your folders are named Pages_34, Pages_36, etc.  In your action add "Execute JavaScript" as the last command then add the following script:

this.saveAs("/*this is the file path to your folder including the last slash*/ " + "Page_" + this.numPages + "/" + this.documentFileName);

If you're folders aren't consistently name and/or don't have the number of pages in the name you will have to create an if statement like this:

var fldrName;

if(this.numPages==36)

{fldrName="The first folder"} else

if(this.numPages==38)

{fldrName="The second folder"} else...etc.

Then pass the variable into the saveAs cPath parameter.  I'm not a Mac user but I believe the file paths us backslashes.  Open a PDF in one of the folders and run the following script in the console to see the path structure then escape backslashes in your script if the paths contain them:

this.path

AidanCable
Participant
December 17, 2024

 Thanks for the response! I have added this to the Execute Javascript function, its not allowing me to click ok - says there is a syntax error - am I missing something?

Sorry 0 knowledge of code here... 

Appreciate the help!

PDF Automation Station
Community Expert
Community Expert
December 17, 2024

Sorry, I forgot the quotes (now corrected).  It should be:

this.saveAs("/Volumes/ClientFolder/Client1/TestFolder/" +"Page_"+ this.numPages+ "/"+this.documentFileName);