lapots
lapots

Reputation: 13395

work with folders using activexobject

I need to create folder,copy it and delete. So I've created several javascript functions - to get path to the folder, delete folder,create and copy folder.

But when I try to run it in google chrome I've got an exception enter image description here

I thought it was problem with ActiveX. But in IE it doesn't work either.

<html>
<head>
    <meta charset="utf-8">
    <script type="text/javasript">
        function onFolder(){
            var ob = new ActiveXObject("Scripting.FileSystemObject");
            var name = document.getElementById("idtextbox1").value;
            var path = document.getElementById("idtextbox2").value;
            var x = path + "\\" + name;
            return x;
        }
        function onCreate(){
            var ob = new ActiveXObject("Scripting.FileSystemObject");
            var path = onFolder();
            var x = ob.CreateFolder(path);
        }
        function onCopy(){
            var ob = new ActiveXObject("Scripting.FileSystemObject");           
            var source = onFolder();
            var dest = document.getElementById("idtextbox3").value;
            ob.CopyFolder(source,dest + "\\");
        }
        function onDelete(){
            var ob = new ActiveXObject("Scripting.FileSystemObject");
            var folder = onFolder();
            ob.DeleteFolder(folder);
        }
    </script>
</head>
<body>
    Folder name<input type="text" id="idtextbox1">
    <br>
    Destination<input type="text" id="idtextbox2">
    <br>
    Copy destination<input type="text" id="idtextbox3">
    <br>
    <input type="button" id="idbutton1" value="Create" onClick="onCreate()">
    <input type="button" id="idbutton2" value="Copy" onClick="onCopy()">
    <input type="button" id="idbutton3" value="Delete" onClick="onDelete()">
</body>
</html>

What's the problem? Is it ActiveX? Because I think javascript functions are correct.

Upvotes: 0

Views: 1321

Answers (1)

Shawn31313
Shawn31313

Reputation: 6052

The big problem is that you are using chrome Chrome. ActiveX only works in IE because it is a non-standard function. And for what you are trying to do, the security level has to be on low which is very unconventional. JavaScript is just not a good language to be trying to access or update a computers file system.

Upvotes: 2

Related Questions