如何:在 Visual Basic 中擷取我的文件目錄的內容

SpecialDirectories 物件可以用來讀取許多 [所有使用者] 目錄,例如 [我的文件] 或 [桌面]

讀取 [我的文件] 資料夾

  • 使用 ReadAllText 方法,讀取特定目錄中每個檔案的文字。 下列程式碼指定目錄和檔案,然後使用 ReadAllText 將它們讀入名為 patients 的字串。

    Dim path As String
    Dim patients As String
    path = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\" & "Patients.txt"
    patients = My.Computer.FileSystem.ReadAllText(path)
    

另請參閱