vb.net get file names in directory?

前端 未结 4 879
灰色年华
灰色年华 2021-02-19 09:14

I have the following code.

Dim text As String = IO.File.ReadAllText(\"C:\\Example.xtp\")

This code is specific to a single file, however I woul

相关标签:
4条回答
  • 2021-02-19 09:17
    System.IO.Directory.GetFiles() 
    

    could help

    0 讨论(0)
  • 2021-02-19 09:28

    Try this:

    Dim text As String = ""
    Dim files() As String = IO.Directory.GetFiles(sFolder)
    
    For Each sFile As String In files
        text &= IO.File.ReadAllText(sFile)
    Next
    
    0 讨论(0)
  • 2021-02-19 09:30

    You will need to use the IO.Directory.GetFiles function.

    Dim files() As String = IO.Directory.GetFiles("c:\")
    
    For Each file As String In files
      ' Do work, example
      Dim text As String = IO.File.ReadAllText(file)
    Next
    
    0 讨论(0)
  • 2021-02-19 09:44
    Dim fileEntries As String() = Directory.GetFiles("YourPath", "*.txt")
    ' Process the list of .txt files found in the directory. '
    Dim fileName As String
    
    For Each fileName In fileEntries
        If (System.IO.File.Exists(fileName)) Then
            'Read File and Print Result if its true
            ReadFile(fileName)
        End If
        TransfereFile(fileName, 1)
    Next
    
    0 讨论(0)
提交回复
热议问题