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