如何:在 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)
    

另请参阅