5

我正在尝试找出一种使用 C# 导航到漫游中的子文件夹的方法。我知道要访问我可以使用的文件夹:

string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

我想要做的是导航到漫游内的文件夹,但不知道如何。我基本上需要做这样的事情:

string insideroaming = string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData\FolderName);

有什么办法可以做到这一点?谢谢。

4

2 回答 2

8

考虑Path.Combine

string dir = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
    "FolderName"
);

它返回类似于:

C:\Users\<用户名>\AppData\Roaming\FolderName

如果您需要获取文件夹内的文件路径,您可以尝试

string filePath = Path.Combine(
    dir,
    "File.txt"
);

要不就

string filePath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
    "FolderName",
    "File.txt"
);
于 2014-09-07T01:17:18.543 回答
-1
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string filePath = Path.Combine(appDataFolder + "\\SubfolderName\\" + "filename.txt");
于 2016-10-19T04:58:26.290 回答