Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

using js script I am trying to create a folder and copy a file

<html>
    <body>
    <script language="JScript">
  
    function copy()
    {
        var myObject, newpath;
        myObject = new ActiveXObject("Scripting.FileSystemObject");
        myObject.CopyFile ("c:\\test.txt", "c:\\newtmp\\myTest.txt");
		document.write("Copy Complete");
		var fs = require('fs');
		var dir = './tmp';
	}

	function create()
    {
         var myObject, newfolder;
        myObject = new ActiveXObject("Scripting.FileSystemObject");
        newfolder = myObject.CreateFolder ("c:\\newtmp\\");
		document.write("Folder creation complete");
    }
   
    </script>
    create folder newtmp and Copy "c:\test.txt" to the existing path: "c:\newtmp\myTest.txt"
    <form name="myForm">
    <input type="Button" value="Copy File" onClick='create();copy()'>
    </form>
    </body>
    </html>

Open in new window

     
Please see above. I can create the folder but I am unable to copy the file. I want to do both operations on same onclick. Please let me know what is wrong.

Also I would like to know if the source is a shared folder \\hostname\share\ , how to copy from the share to local drive folder.

Appreciate your help!
Thanks
DevSupport
Avatar of James Bilous
James Bilous
Flag of United States of America image

What error are you getting, if any? Why prints out?
Avatar of DevSupport
DevSupport

ASKER

oh sorry, it creates the folder but doesnt copy the file into the folder. It doesnt give any error as such.

Thanks
Amrith
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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
have you enabled ActiveX controls to run in IE.
if you get this to work fully, you'll only be able to run it locally, as this would be considered a huge security risk. If I ever went to a website that created folders and files on my local machine, I would be horrified.
@leakim971
I ran the code locally and it gave me ok1 but nothing else.
@Julian Hansen:
I have enabled ActiveX
@Big Monty
We would have this url accessible only on specific systems designated to run scripts.
I am closing this question as I am going to follow another approach.
Thanks anyways for the help so far.