[RESOLVED] reading the content of a text file...
Hi,
The following script reads only the first line of the text file..
How can I code it so that it is able to read all of the lines in the file..
Thanks.
VB Code:
<script>
function ReadIt() {
var filename = 'c:/27temp.txt';
if (confirm('Do you want to see what we wrote in your file?')) {
var fso, a, ForReading;
ForReading = 1;
fso = new ActiveXObject('Scripting.FileSystemObject');
file = fso.OpenTextFile(filename, ForReading, false);
var name = file.readline();
var password = file.readline();
file.Close();
document.write(name + '<br>');
document.write(password);
alert(name +"...." + password)
}
}
</SCRIPT>
Re: reading the content of a text file...
I don't know what is the format of your text file, and I don't know how you want the windows to alert.. Here is what I come up with .
The text file format is like:
Andy
123
Mary
456
Code:
<script>
function ReadIt() {
var filename = 'test.txt';
if (confirm('Do you want to see what we wrote in your file?')) {
var fso, a, ForReading;
ForReading = 1;
fso = new ActiveXObject('Scripting.FileSystemObject');
file = fso.OpenTextFile(filename, ForReading, false);
while (!file.AtEndOfStream) {
var name = file.readline();
var password = file.readline();
document.write(name + "<br>");
document.write(password + "<br>");
}
alert(name +"...." + password);
file.Close();
}
}
</SCRIPT>
<body onLoad=ReadIt()>
I think one var for file.readline() is enough but again I dont' know what format of the text file is.
Re: reading the content of a text file...
I think what I need is a "for loop" to read the content of the text file located in "C:\"
Could you anyone please add a "for-next" loop so I can read display the output...?
thanks
VB Code:
<html><head>
<SCRIPT LANGUAGE='JavaScript'>
var password='theirpassword şifreeeeeee';
var name='username......isim';
function WriteToFile() {
var filename = 'c:/27temp.txt';
var fso = new ActiveXObject('Scripting.FileSystemObject');
if (fso.FileExists(filename)) {
var a, ForAppending, file;
ForAppending = 8;
file = fso.OpenTextFile(filename, ForAppending, false);
file.WriteLine(name);
file.WriteLine(password);
}
else {
var file = fso.CreateTextFile(filename, true);
file.WriteLine(password);
file.WriteLine(name);
}
file.Close();
}
function ReadIt() {
var filename = 'c:/27temp.txt';
if (confirm('Do you want to see what we put on your computer?')) {
var fso, a, ForReading;
ForReading = 1;
fso = new ActiveXObject('Scripting.FileSystemObject');
file = fso.OpenTextFile(filename, ForReading, false);
var name = file.readline();
var password = file.readline();
file.Close();
document.write(name + '<br>');
document.write(password);
}
}
</SCRIPT>
</head>
<body onload='WriteToFile();ReadIt()'>
</body>
</html>