Link to home
Start Free TrialLog in
Avatar of amateur6
amateur6Flag for United States of America

asked on

NON-BROWSER javascript save file to disk?

Hello -

I know that you can't do this in a browser, but I'm hoping that it IS possible to use javascript to do it in. Specifically, I want to assign the script to a link in Acrobat - the files will all be on a CD.

I need to save a file from the CD to the user's hard drive.

Can it be done? 500 points on the line because I need to know ASAP. Ideally, I need a turnkey script too - I'm not wise in the ways of the java...

Thanks in advance!
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

If you want to copy a file from CD to Disk, then use BAT files for that.
Why do you it to be done in JaveScript? Do you start that operation from a browser page opened from the CD?
Avatar of amateur6

ASKER

Two things - 1) I need a cross-platform solution (if I had to I could probably use one PDF for each platform) and 2) I don't know if I can get to a BAT from the PDF. Could I call one using a javascript? (Then I could use BAT for PC and AppleScript for Mac)
JavaScript alone cannot copy files. It needs always some OS side support.
Here is how you would do it on Windows:

var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("CMD /C copy D:\\temp\\file.txt C:\\");

cool, cool - I'm obviously wrong, because I always thought ActiveX was a browser thing. How far back in Windows versions can I use it?

And presumably that's just a snippet - or is that all the code I'd need? THANKS!
Oh, sorry - and are CD drives always "D:\\", and/or do I need to reference the name of the CD anywhere? Thanks again!
The upper snippet is the complette content of a file with the extension .js which can be executed from command line.
The executor of that batch JavaScripts is the WindowsScriptHost engine.
The WSH is embedded since Win98 in the system.

To decide which drive letter is the CD is not trivial because you have to enumerate all drives and look for media type. Also you can have two or more CD drives.
Please explain a bit more what you try to do.

Sorry, let me try to be more clear.

I'm making a CD which will have a PDF Catalog and separate hi-res image files. Within the PDF I can make a link/button which will execute a javascript (this is part of Acrobat's functionality). I would like that javascript to enable me to allow the user to select a location to save a particular hi-res file to their hard drive from the CD.

The reason I was asking about the drive letter was because it's in the code snippet, which made me wonder "what if the CD's not IN the D drive?" and "how likely is that"? and "is there another way to reference it (ie, by the CD's name)?"

Thank you, thank you, thank you!

I still have the cross-platform problem, but I'll deal with that separately...
Ok, then give NO drive letter.
The Acrobat system is supposed to act on the current drive where the Application is running.
Use simply the absolute or the relative directory path on the CD.

Okay, no luck. And no handy errors or anything - just click = nothing. Does that, in itself, indicate anything?

I used this (probably wrong somewhere):

var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("CMD /C copy images\\red_esquire C:\\");

What did I break? Thanks!
To get closer do first test with some knowen files. Fo example, copy some test file from one directory on C: to some other directory.
If that works, then try someting like this:

var oExec = WshShell.Exec("CMD /C DIR > C:\\dir.txt");

In the C:\dir.txt you should see the actual application working directory and use it as relative path.
Oh, also switch your Windows Explorer to show you the file Extensions also for known file types.
I assume your image file name is like this:
var oExec = WshShell.Exec("CMD /C copy images\\red_esquire.gif C:\\");

Oops, it's actually "red_esquire.jpg" ... let me try that (and eat some lunch).  :-)
I was hoping it was my bad name or path, but after exhaustive testing (and moving stuff), it's not. Pity.

When you say "For example, copy some test file from one directory on C: to some other directory", how do I go about doing that? As I mentioned, I'm NOT a javascript guy.

And then "var oExec = WshShell.Exec("CMD /C DIR > C:\\dir.txt");" I think I get it - that will write out a directory path? But do I put it after the "var WshShell" line?

Thanks thanks thanks!
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia 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
Thanks for all the help!! I'm on to a different project just now, but give me a day or two. AND thanks for your patience!