Share via


HOW TO:在 Visual Basic 中擷取我的文件目錄的內容

更新:2007 年 11 月

My.Computer.FileSystem.SpecialDirectories 物件可用於讀取 [All Users] 目錄中的數個目錄,例如 [我的文件] 或 [桌面]。

若要讀取我的文件資料夾

  • 使用 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)
    

請參閱

參考

My.Computer.FileSystem.SpecialDirectories 物件

My.Computer.FileSystem.SpecialDirectories 物件成員

My.Computer.FileSystem.ReadAllText 方法