Reputation: 1314
I am new to JavaScript. I need to move a file to another directory using JavaScript. How can simply move that file with JavaScript?
How can I solve this?
I tried this, but it didn't work....
<html>
<h2>Move file in JavaScript</h2>
<script language="javascript">
function moveFile(){
var object = new ActiveXObject("Scripting.FileSystemObject");
var file = object.GetFile("Table1.xml");
file.Move("./Docus/");
document.write("File is moved successfully");
}
</script>
<form>
<input type="Button" value="Move File" onClick='moveFile()'>
</form>
</html>
How can I do this, anyone?
Upvotes: 2
Views: 50257
Reputation: 856
As far as I understand the problem which you're trying to solve is to create some kind of rich UI (user interface), where user can drag-and-drop files through directory tree.
Well that's is surely possible, but the way to make it right - and with that I mean make it cross-browser compatible and secure - is with a serverside script (PHP, ASP.Net, whatever) running behind it, providing all the data and file-system operations, with a security layer on top of it.
And if you want an unsecure, MS Internet Explorer only solution - sure you can use ActiveX objects.
Upvotes: 1
Reputation: 20820
Tried this code, working perfectly :
function moveFile(){
var object = new ActiveXObject("Scripting.FileSystemObject");
var file = object.GetFile("C:\\wamp\\www\\phptest.php");
file.Move("C:\\wamp\\");
document.write("File is moved successfully");
}
In your code, issue seems to be in file path "./Docus/". Try to put absolute path and then check.
Upvotes: 3