Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

FileSystemObject - Text File problems

aaronjones3593aaronjones3593 Posts: 122Member
I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding
to the end of every line...

Is there some sort of loop that can do this for me?

I tried something alond the lines of

[code]
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ofo = fso.OpenTextFile("somefilewithiteration.txt");

for (i=0; i<ofo.length; i++)
{
text += ofo.ReadLine();
ofo.NextLine();
}
[/code]

Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(

Anyone got some code that can fix this?

Thanks in advance,
Aaron


-( Aaron )-

"Alcohol aint the answer, but atleast you forget the question"

Comments

  • zibadianzibadian Posts: 6,349Member
    : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    :
    : Is there some sort of loop that can do this for me?
    :
    : I tried something alond the lines of
    :
    : [code]
    : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    :
    : for (i=0; i'[/b];
    : ofo.NextLine();
    : }
    : [/code]
    :
    : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    :
    : Anyone got some code that can fix this?
    :
    : Thanks in advance,
    : Aaron
    :
    :
    : -( Aaron )-
    :
    : "Alcohol aint the answer, but atleast you forget the question"
    :
    See bold part in code above.
  • aaronjones3593aaronjones3593 Posts: 122Member
    : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : :
    : : Is there some sort of loop that can do this for me?
    : :
    : : I tried something alond the lines of
    : :
    : : [code]
    : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : :
    : : for (i=0; i<ofo.length; i++)
    : : {
    : : text += ofo.ReadLine()[b]+''[/b];
    : : ofo.NextLine();
    : : }
    : : [/code]
    : :
    : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : :
    : : Anyone got some code that can fix this?
    : :
    : : Thanks in advance,
    : : Aaron
    : :
    : :
    : : -( Aaron )-
    : :
    : : "Alcohol aint the answer, but atleast you forget the question"
    : :
    : See bold part in code above.
    :
    Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?


    -( Aaron )-

    "Alcohol aint the answer, but atleast you forget the question"

  • zibadianzibadian Posts: 6,349Member
    : : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : : :
    : : : Is there some sort of loop that can do this for me?
    : : :
    : : : I tried something alond the lines of
    : : :
    : : : [code]
    : : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : : :
    : : : for (i=0; i<ofo.length; i++)
    : : : {
    : : : text += ofo.ReadLine()[b]+''[/b];
    : : : ofo.NextLine();
    : : : }
    : : : [/code]
    : : :
    : : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : : :
    : : : Anyone got some code that can fix this?
    : : :
    : : : Thanks in advance,
    : : : Aaron
    : : :
    : : :
    : : : -( Aaron )-
    : : :
    : : : "Alcohol aint the answer, but atleast you forget the question"
    : : :
    : : See bold part in code above.
    : :
    : Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?
    :
    :
    : -( Aaron )-
    :
    : "Alcohol aint the answer, but atleast you forget the question"
    :
    :
    I think readLine() already advances to the next line, and nextLine() isn't necessary in this case.
  • aaronjones3593aaronjones3593 Posts: 122Member
    : : : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : : : :
    : : : : Is there some sort of loop that can do this for me?
    : : : :
    : : : : I tried something alond the lines of
    : : : :
    : : : : [code]
    : : : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : : : :
    : : : : for (i=0; i<ofo.length; i++)
    : : : : {
    : : : : text += ofo.ReadLine()[b]+''[/b];
    : : : : ofo.NextLine();
    : : : : }
    : : : : [/code]
    : : : :
    : : : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : : : :
    : : : : Anyone got some code that can fix this?
    : : : :
    : : : : Thanks in advance,
    : : : : Aaron
    : : : :
    : : : :
    : : : : -( Aaron )-
    : : : :
    : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : :
    : : : See bold part in code above.
    : : :
    : : Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?
    : :
    : :
    : : -( Aaron )-
    : :
    : : "Alcohol aint the answer, but atleast you forget the question"
    : :
    : :
    : I think readLine() already advances to the next line, and nextLine() isn't necessary in this case.
    :
    oh thankyou. i have searched the internet over and over, but couldnt find anything to do with this particular function in great detail. it seems that more documentation is reqwuired by some developers on a lot of things lol.


    -( Aaron )-

    "Alcohol aint the answer, but atleast you forget the question"

  • zibadianzibadian Posts: 6,349Member
    : : : : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : : : : :
    : : : : : Is there some sort of loop that can do this for me?
    : : : : :
    : : : : : I tried something alond the lines of
    : : : : :
    : : : : : [code]
    : : : : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : : : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : : : : :
    : : : : : for (i=0; i<ofo.length; i++)
    : : : : : {
    : : : : : text += ofo.ReadLine()[b]+''[/b];
    : : : : : ofo.NextLine();
    : : : : : }
    : : : : : [/code]
    : : : : :
    : : : : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : : : : :
    : : : : : Anyone got some code that can fix this?
    : : : : :
    : : : : : Thanks in advance,
    : : : : : Aaron
    : : : : :
    : : : : :
    : : : : : -( Aaron )-
    : : : : :
    : : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : : :
    : : : : See bold part in code above.
    : : : :
    : : : Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?
    : : :
    : : :
    : : : -( Aaron )-
    : : :
    : : : "Alcohol aint the answer, but atleast you forget the question"
    : : :
    : : :
    : : I think readLine() already advances to the next line, and nextLine() isn't necessary in this case.
    : :
    : oh thankyou. i have searched the internet over and over, but couldnt find anything to do with this particular function in great detail. it seems that more documentation is reqwuired by some developers on a lot of things lol.
    :
    :
    : -( Aaron )-
    :
    : "Alcohol aint the answer, but atleast you forget the question"
    :
    :
    According to this http://www.asptutorial.info/sscript/Readingfile.asp, readLine() also reads the line ending. If you want to skip a line, use the skipLine() method.
    More info can also be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/8b99eead-e2bd-45c6-9660-bbbfeec192f0.asp
  • aaronjones3593aaronjones3593 Posts: 122Member
    : : : : : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : : : : : :
    : : : : : : Is there some sort of loop that can do this for me?
    : : : : : :
    : : : : : : I tried something alond the lines of
    : : : : : :
    : : : : : : [code]
    : : : : : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : : : : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : : : : : :
    : : : : : : for (i=0; i<ofo.length; i++)
    : : : : : : {
    : : : : : : text += ofo.ReadLine()[b]+''[/b];
    : : : : : : ofo.NextLine();
    : : : : : : }
    : : : : : : [/code]
    : : : : : :
    : : : : : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : : : : : :
    : : : : : : Anyone got some code that can fix this?
    : : : : : :
    : : : : : : Thanks in advance,
    : : : : : : Aaron
    : : : : : :
    : : : : : :
    : : : : : : -( Aaron )-
    : : : : : :
    : : : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : : : :
    : : : : : See bold part in code above.
    : : : : :
    : : : : Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?
    : : : :
    : : : :
    : : : : -( Aaron )-
    : : : :
    : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : :
    : : : :
    : : : I think readLine() already advances to the next line, and nextLine() isn't necessary in this case.
    : : :
    : : oh thankyou. i have searched the internet over and over, but couldnt find anything to do with this particular function in great detail. it seems that more documentation is reqwuired by some developers on a lot of things lol.
    : :
    : :
    : : -( Aaron )-
    : :
    : : "Alcohol aint the answer, but atleast you forget the question"
    : :
    : :
    : According to this http://www.asptutorial.info/sscript/Readingfile.asp, readLine() also reads the line ending. If you want to skip a line, use the skipLine() method.
    : More info can also be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/8b99eead-e2bd-45c6-9660-bbbfeec192f0.asp
    :

    Those sites talk about ASP and VBScript. I am using JScript, but now after looking at that I might switch to VBScript, since I know a little of it. JScript was the first language I ever learnt so it's my strongest, but I guess times change... :)

    By the way, I only used JScript because I am not running this application in a webserver environment. I am running it in a webpage stored on a local harddisk. So the URL starts with file:// not http://, just thought I'd mention that because that means I cannot use ASP.


    -( Aaron )-

    "Alcohol aint the answer, but atleast you forget the question"

  • zibadianzibadian Posts: 6,349Member
    : : : : : : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : : : : : : :
    : : : : : : : Is there some sort of loop that can do this for me?
    : : : : : : :
    : : : : : : : I tried something alond the lines of
    : : : : : : :
    : : : : : : : [code]
    : : : : : : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : : : : : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : : : : : : :
    : : : : : : : for (i=0; i<ofo.length; i++)
    : : : : : : : {
    : : : : : : : text += ofo.ReadLine()[b]+''[/b];
    : : : : : : : ofo.NextLine();
    : : : : : : : }
    : : : : : : : [/code]
    : : : : : : :
    : : : : : : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : : : : : : :
    : : : : : : : Anyone got some code that can fix this?
    : : : : : : :
    : : : : : : : Thanks in advance,
    : : : : : : : Aaron
    : : : : : : :
    : : : : : : :
    : : : : : : : -( Aaron )-
    : : : : : : :
    : : : : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : : : : :
    : : : : : : See bold part in code above.
    : : : : : :
    : : : : : Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?
    : : : : :
    : : : : :
    : : : : : -( Aaron )-
    : : : : :
    : : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : : :
    : : : : :
    : : : : I think readLine() already advances to the next line, and nextLine() isn't necessary in this case.
    : : : :
    : : : oh thankyou. i have searched the internet over and over, but couldnt find anything to do with this particular function in great detail. it seems that more documentation is reqwuired by some developers on a lot of things lol.
    : : :
    : : :
    : : : -( Aaron )-
    : : :
    : : : "Alcohol aint the answer, but atleast you forget the question"
    : : :
    : : :
    : : According to this http://www.asptutorial.info/sscript/Readingfile.asp, readLine() also reads the line ending. If you want to skip a line, use the skipLine() method.
    : : More info can also be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/8b99eead-e2bd-45c6-9660-bbbfeec192f0.asp
    : :
    :
    : Those sites talk about ASP and VBScript. I am using JScript, but now after looking at that I might switch to VBScript, since I know a little of it. JScript was the first language I ever learnt so it's my strongest, but I guess times change... :)
    :
    : By the way, I only used JScript because I am not running this application in a webserver environment. I am running it in a webpage stored on a local harddisk. So the URL starts with file:// not http://, just thought I'd mention that because that means I cannot use ASP.
    :
    :
    : -( Aaron )-
    :
    : "Alcohol aint the answer, but atleast you forget the question"
    :
    :
    The implementation of the FileSystemObject still remains the same, no matter which language is used to call it. Since the implementation remains the same, the method readLine() is the same for both JScript and VBScript. Hence these pages still apply to your problem.
    Remember that "new ActiveXObject()" loads an externally defined object into the browser. The implementation of that object is not subject to the limitations of the calling language.
  • aaronjones3593aaronjones3593 Posts: 122Member
    : : : : : : : : I have the following code. At the moment, the code just prints the entire contents of a text file. However, it does not take into account lines and I have too many text files to go through them adding to the end of every line...
    : : : : : : : :
    : : : : : : : : Is there some sort of loop that can do this for me?
    : : : : : : : :
    : : : : : : : : I tried something alond the lines of
    : : : : : : : :
    : : : : : : : : [code]
    : : : : : : : : var fso = new ActiveXObject("Scripting.FileSystemObject");
    : : : : : : : : var ofo = fso.OpenTextFile("somefilewithiteration.txt");
    : : : : : : : :
    : : : : : : : : for (i=0; i<ofo.length; i++)
    : : : : : : : : {
    : : : : : : : : text += ofo.ReadLine()[b]+''[/b];
    : : : : : : : : ofo.NextLine();
    : : : : : : : : }
    : : : : : : : : [/code]
    : : : : : : : :
    : : : : : : : : Is there an equivelent NextLine() function or something like that? At the moment, and as far as I can remember, I have only been able to use ReadLine() to read line 1 and then it gives up. As a temporary solution to my problem, I use the ReadAll() method, but that doesn't print a CRLF for the end of every line... :(
    : : : : : : : :
    : : : : : : : : Anyone got some code that can fix this?
    : : : : : : : :
    : : : : : : : : Thanks in advance,
    : : : : : : : : Aaron
    : : : : : : : :
    : : : : : : : :
    : : : : : : : : -( Aaron )-
    : : : : : : : :
    : : : : : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : : : : : :
    : : : : : : : See bold part in code above.
    : : : : : : :
    : : : : : : Yes i gathered i had to do that, but im looking for the correction to ofo.NextLine(). it says object does not support this property or method. what is the correct function?
    : : : : : :
    : : : : : :
    : : : : : : -( Aaron )-
    : : : : : :
    : : : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : : : :
    : : : : : :
    : : : : : I think readLine() already advances to the next line, and nextLine() isn't necessary in this case.
    : : : : :
    : : : : oh thankyou. i have searched the internet over and over, but couldnt find anything to do with this particular function in great detail. it seems that more documentation is reqwuired by some developers on a lot of things lol.
    : : : :
    : : : :
    : : : : -( Aaron )-
    : : : :
    : : : : "Alcohol aint the answer, but atleast you forget the question"
    : : : :
    : : : :
    : : : According to this http://www.asptutorial.info/sscript/Readingfile.asp, readLine() also reads the line ending. If you want to skip a line, use the skipLine() method.
    : : : More info can also be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/8b99eead-e2bd-45c6-9660-bbbfeec192f0.asp
    : : :
    : :
    : : Those sites talk about ASP and VBScript. I am using JScript, but now after looking at that I might switch to VBScript, since I know a little of it. JScript was the first language I ever learnt so it's my strongest, but I guess times change... :)
    : :
    : : By the way, I only used JScript because I am not running this application in a webserver environment. I am running it in a webpage stored on a local harddisk. So the URL starts with file:// not http://, just thought I'd mention that because that means I cannot use ASP.
    : :
    : :
    : : -( Aaron )-
    : :
    : : "Alcohol aint the answer, but atleast you forget the question"
    : :
    : :
    : The implementation of the FileSystemObject still remains the same, no matter which language is used to call it. Since the implementation remains the same, the method readLine() is the same for both JScript and VBScript. Hence these pages still apply to your problem.
    : Remember that "new ActiveXObject()" loads an externally defined object into the browser. The implementation of that object is not subject to the limitations of the calling language.
    :

    Ah, we learn something new everyday I guess.

    I will try it then, and let you know if it works or not...

    Thanks,



    -( Aaron )-

    "Pain does not hurt, if it's all you've ever felt."

Sign In or Register to comment.