Forum Discussion

bruno_mesquita's avatar
bruno_mesquita
New Contributor
11 years ago

Open File .txt Script (VBScript)


My question is as follows:


 


I have a file with extension .txt stored on my hard disk, i want to open it via VBScript. Is it possible? In what way?


 


Will can help me please?



Thank you.

4 Replies

  • mark_addinall's avatar
    mark_addinall
    Occasional Contributor


    'Create Object



    Dim fso,f



    Set fso = CreateObject("Scripting.FileSystemObject")



     



    'Open the text file



    Set f = fso.OpenTextFile(PathToFile,1,True)


  • mark_addinall's avatar
    mark_addinall
    Occasional Contributor
    If you want to smply check that the contents of the file are what you expect then you can add the file to your stores container in your test project and use the various methods of comparison available - Files.Compare() comes to mind.



    If you want to store the text of the file in memory and do something with it then you will need to have a look at the references for the FileSystemObject I mentioned earlier.



    http://msdn.microsoft.com/en-us/library/aa242706(v=vs.60).aspx

     or



    http://www.w3schools.com/asp/asp_ref_filesystem.asp
  • Hello, I've tried both solutions provided and none of them solve my problem. What I want to achieve is to open the file itself, so that later can perform validations on the content of it. Any idea how can I do this?



    Thank you.



    Greetings.