CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169

    Unhappy FileSystemObject

    Does anybody know how to use FileSystemObject in VB.NET?

    I'm trying to go into a folder/directory to loop through the files and within each file, look for a specific item.

    Any sample code?

    Or there's a differetn and better way of searching files?

    Thanks!

  2. #2
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169
    Never mind. I've got it.
    Code:
            Dim oFolder As Directory
            Dim oFile As FileStream
            Dim oReader As StreamReader
            Dim sFilename As String()
            Dim sContents As String
            Dim i As Integer
            sFilename = oFolder.GetFiles("C:\Directory\")
    
            For i = 0 To UBound(sFilename)
                oFile = New FileStream(sFilename(i), FileMode.OpenOrCreate, FileAccess.Read)
                oReader = New StreamReader(oFile)
                sContents = oReader.ReadToEnd
                oReader.Close()
           
                oReader = Nothing
                oFile = Nothing
            Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured