none
請問怎樣讀取資料夾下面所有.html檔? RRS feed

  • 問題

  •  

    fileinfo然後path那邊打 *.html

    就行了?

    我想把資料夾下的子資料夾的.html也一起讀取

    請問有甚麼方法?

    2008年3月10日 上午 04:01

解答

  • Code Snippet

    Imports System
    Imports System.IO

    Class App
        Public Shared Sub Main()
            ' Specify the directory you want to manipulate.
            Dim path As String = "c:\\"
            Dim searchPattern As String = "*.htm"

            Dim di As DirectoryInfo = New DirectoryInfo(path)
            Dim directories() As DirectoryInfo = _
                di.GetDirectories(searchPattern, SearchOption.AllDirectories)

            Dim files() As FileInfo = _
                di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly)

            Console.WriteLine( _
                "Directories that begin with the letter 'c' in {0}", path)
            Dim dir As DirectoryInfo
            For Each dir In directories
                Console.WriteLine( _
                    "{0,-25} {1,25}", dir.FullName, dir.LastWriteTime)
            Next dir

            Console.WriteLine()
            Console.WriteLine( _
                "Files that begin with the letter 'c' in {0}", path)
            Dim file As FileInfo
            For Each file In files
                Console.WriteLine( _
                    "{0,-25} {1,25}", file.Name, file.LastWriteTime)
            Next file
        End Sub
    End Class

     

     

    2008年3月10日 上午 04:14
    版主

所有回覆

  • Code Snippet

    Imports System
    Imports System.IO

    Class App
        Public Shared Sub Main()
            ' Specify the directory you want to manipulate.
            Dim path As String = "c:\\"
            Dim searchPattern As String = "*.htm"

            Dim di As DirectoryInfo = New DirectoryInfo(path)
            Dim directories() As DirectoryInfo = _
                di.GetDirectories(searchPattern, SearchOption.AllDirectories)

            Dim files() As FileInfo = _
                di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly)

            Console.WriteLine( _
                "Directories that begin with the letter 'c' in {0}", path)
            Dim dir As DirectoryInfo
            For Each dir In directories
                Console.WriteLine( _
                    "{0,-25} {1,25}", dir.FullName, dir.LastWriteTime)
            Next dir

            Console.WriteLine()
            Console.WriteLine( _
                "Files that begin with the letter 'c' in {0}", path)
            Dim file As FileInfo
            For Each file In files
                Console.WriteLine( _
                    "{0,-25} {1,25}", file.Name, file.LastWriteTime)
            Next file
        End Sub
    End Class

     

     

    2008年3月10日 上午 04:14
    版主
  • 謝謝你

    原來真的是*.HTML

    2008年3月10日 上午 04:28