Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2105
  • Last Modified:

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!
0
amateur6
Asked:
amateur6
  • 8
  • 7
1 Solution
 
ZvonkoSystems architectCommented:
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?
0
 
amateur6Author Commented:
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)
0
 
ZvonkoSystems architectCommented:
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:\\");

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
amateur6Author Commented:
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!
0
 
amateur6Author Commented:
Oh, sorry - and are CD drives always "D:\\", and/or do I need to reference the name of the CD anywhere? Thanks again!
0
 
ZvonkoSystems architectCommented:
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.

0
 
amateur6Author Commented:
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...
0
 
ZvonkoSystems architectCommented:
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.

0
 
amateur6Author Commented:
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!
0
 
ZvonkoSystems architectCommented:
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.
0
 
ZvonkoSystems architectCommented:
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:\\");

0
 
amateur6Author Commented:
Oops, it's actually "red_esquire.jpg" ... let me try that (and eat some lunch).  :-)
0
 
amateur6Author Commented:
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!
0
 
ZvonkoSystems architectCommented:
First test:

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


Second test:

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

After first test you should have a copy of a file from c:\app\images\red_esquire.jpg  copied to c:\temp
Then you know that your copy syntax is correct.

Now you have to know what the drive letter and the application directory path is when you do the copy.
The DIR command tells you the actual directory. You can read it in the file C:\dir.txt
Based on the directory information you can adjust the relative copy command.

0
 
amateur6Author Commented:
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!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now