Solved

JavaScript loop through directory, get filenames

Posted on 2011-09-07
12
2,696 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:EMB01
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 7

Assisted Solution

by:Gewgala
Gewgala earned 150 total points
ID: 36500886
I don't think this is possible because it seems it would violate security restrictions.  Javascript can't do any kind of directory browsing.  You could guess, using a regex wild card like you say, but that would take so much computer power because you would in theory be trying to match every single character combination for a file.  You have to guess, you can't be given a list of files, so you're trying to guess every combination from a file with 1 character to a file with whatever the limit the OS puts on file name lengths.  
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 36500887
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.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 36500899
This is Adobe PDF specific scripting, nothing to do with a web browser...
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 36500909
Oh.  I thought it was some kind of embedded adobe reader in a web page.  My mistake.
0
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 100 total points
ID: 36500939
I haven't tested this, only looking through the api for you...
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

But the Search object might work, search for documents that contain "Acrobat"
search.docInfo = true;
search.query("Acrobat","Folder","/c/myDocuments");

Open in new window

0
 
LVL 14

Author Comment

by:EMB01
ID: 36502116
>>  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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 250 total points
ID: 36502501
No, you cannot run an Acrobat process automatically, but have you looked into running your action on the contents of a directory? It would then always process all files in that directory. You would not even use JavaScript in that case. I assume that you have Acrobat X (otherwise you would have used the term batch sequence instead of action). If that's not the case, let me know which version of Acrobat you are using.
0
 
LVL 14

Author Comment

by:EMB01
ID: 36502529
>>  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 :).
0
 
LVL 14

Author Comment

by:EMB01
ID: 36502705
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
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36502807
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).
0
 
LVL 14

Author Comment

by:EMB01
ID: 36503148
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?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36503287
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).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now