<script>
function load()
{
var fso, f, r;
var ForReading = 1, ForWriting = 2;
var str='Scripting.FileSystemObject';
fso = new ActiveXObject(str);
var file = 'c:/testfile.txt';
f = fso.OpenTextFile(file, ForWriting, true);
var text ='Hello world!';
f.Write(text);
f.Close();
alert('done');
}
load();
</script>
to create a file on my Hard Drive by saving the page simply in Desktop and execute it by double clicking the page
this is a simple html page.
but i want to create this file on my localhost by putting this html file in my localhost and i want to execute this file like
Code:
http://localhost/dir/file.htm
but it does not create the file on localhost with this code
Code:
<script>
function load()
{
var fso, f, r;
var ForReading = 1, ForWriting = 2;
var str='Scripting.FileSystemObject';
fso = new ActiveXObject(str);
var file = 'http://localhost/dir/testfile.txt';
f = fso.OpenTextFile(file, ForWriting, true);
var text ='Hello world!';
f.Write(text);
f.Close();
alert('done');
}
load();
</script>
and shows an error like
Code:
bad file name or number
please rate the post if this is useful. And also never forget to mark the thread as [Resolved] when your problem is solved
FileSystemObject looks at exactly what it says...the system's disk. It cannot tell what localhost is since it is not part of a web server. I'm sorry, but you are going to have to specify system relative path.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
That is exactly what it is doing. For instance, let's say you're using IIS and the root for your web page is in c:\inetpub\wwwroot\myapp. You likely have a file in there called index.html (or index.php etc. etc.). When you use a *relative path*, it will start at the root directory of the web. Try to stay away from fully qualified paths (such as C:\my\path\my.file) as you will likely run into permission issues. If you specify the path "files/data.dat" then you will actually be referencing the file c:\inetpub\wwwroot\myapp\files\data.dat. I can't really define what a relative path is any clearer than that.
Meddle not in the affairs of dragons, human, for thou art crunchy and taste good with ketchup.
Bookmarks