• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3803
  • Last Modified:

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

0
EMB01
Asked:
EMB01
  • 4
  • 3
  • 3
  • +1
3 Solutions
 
GewgalaCommented:
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
 
GewgalaCommented:
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
 
RobOwner (Aidellio)Commented:
This is Adobe PDF specific scripting, nothing to do with a web browser...
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
GewgalaCommented:
Oh.  I thought it was some kind of embedded adobe reader in a web page.  My mistake.
0
 
RobOwner (Aidellio)Commented:
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
 
EMB01Author Commented:
>>  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
 
Karl Heinz KremerCommented:
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
 
EMB01Author Commented:
>>  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
 
EMB01Author Commented:
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
 
Karl Heinz KremerCommented:
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
 
EMB01Author Commented:
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
 
Karl Heinz KremerCommented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now