Link to home
Start Free TrialLog in
Avatar of EMB01
EMB01Flag for United States of America

asked on

JavaScript loop through directory, get filenames

I am using AcroJS (adobe acrobat javascript) to load a file from my computer into acrobat reader.  However, I want to load all PDF files in a directory.  Is there anyway to do this?  Perhaps something like this will help you understand what I'm after:

app.openDoc("/w/Ametek/catalogfiles.ametektip.com/Generated/Catalogs/5/cn/"+ * + ".pdf");

(where * is the wildcard, allowing any filename to be selected)

Ideally, I would like to loop through the entire directory and get all PDF files; but I don't know if that's possible...
var myOpen = app.trustedFunction(
    function()
    {
        try {
			app.openDoc("/w/Ametek/catalogfiles.ametektip.com/Generated/Catalogs/5/cn/"+);
		} catch (e) {
			app.alert('err')
		};
	});
	myOpen();

Open in new window

SOLUTION
Avatar of Gewgala
Gewgala
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What you would have to do, is get the list of files on the server.  If you are using PHP or ASP.NET or something like that, you can get a list of files in the desired directory, and then write them out to a javascript array.  You could then iterate through the array in your javascript code and that should work fine.  I don't think you can do this without some kind of server interaction though.
Avatar of Rob
This is Adobe PDF specific scripting, nothing to do with a web browser...
Oh.  I thought it was some kind of embedded adobe reader in a web page.  My mistake.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EMB01

ASKER

>>  But the Search object might work, search for documents that contain "Acrobat"

Thanks, that gets me closer.  But, I think I'm going to just feed it the direct filenames since I know what they should be.

Basically, I have an acrobat action that saves all selected documents from PDF to POSTSCRIPT.  I want to make the process even more automated.

Is it possible to run acrobat automatically, say, once a day?  Or, is it possible to run an acrobat action automatically?  I want these files in this directory to be converted to POSTSCRIPT automatically, instead of having to open acrobat and click "run js" and selecting all the files...

Thanks for your help.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EMB01

ASKER

>>  I assume that you have Acrobat X

I am using Acrobat X.  

>>  have you looked into running your action on the contents of a directory?

Please explain :).
Avatar of EMB01

ASKER

Oh, I see what you mean...  Yes, I can run the action on a directory; however, that still requires me to start acrobat, doesn't it?  I want to not have to start acrobat at all.  Something like how this thing works (creates a batch file and runs from command line):

"AutoBatch™ is an advanced plug-in for Adobe® Acrobat Professional® software. AutoBatch™ adds a command-line batch file functionality to the Adobe® Acrobat Professional®. It allows users to execute any existing Acrobat batch sequence from a command-line prompt or a batch file."

Ref.  http://www.evermap.com/autobatch.asp#tag2
As you can see from the link you've provided, something like that requires more than just Acrobat (in this case, I assume an Acrobat plug-in). With just Acrobat, that's not possible. Also, Adobe does not like it when you use Acrobat in a "server like" environment where potentially more than just one user can access and make use of Acrobat (see the EULA you've agreed to when you installed Acrobat for more details).
Avatar of EMB01

ASKER

SO, this has to be done via plugin?  Can plugins be written in javascript?  I can't find any api reference or resources on writing adobe plugins from adobe?  Do they provide such documentation, and if so, can someone please share it with me?
No, plugins need to be written in C/C++. You can find the Acrobat SDK at http://www.adobe.com/devnet/acrobat.html
Let me warn you however: Getting familiar with the Acrobat SDK is a long process, and it would be much cheaper and quicker to buy the product you linked to earlier (I don't know if it would work with Acrobat X, that's something you would have to find out).