C#如何扫描文件夹,然后将扫描的名称存储为字符串

C#如何扫描文件夹,然后将扫描的名称存储为字符串,c#,path,directory,C#,Path,Directory,我需要得到一个文件夹路径,一些文件在每台计算机上有不同的名称。为此,我需要用随机生成的名称扫描包含此文件的文件夹,然后将该文件夹的名称存储为字符串,以便添加到路径中 这是我的密码: string mypath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string mypath1 = @"\Roaming\Mozilla\Firefox\Profiles\"; string mypath2 =

我需要得到一个文件夹路径,一些文件在每台计算机上有不同的名称。为此,我需要用随机生成的名称扫描包含此文件的文件夹,然后将该文件夹的名称存储为字符串,以便添加到路径中

这是我的密码:

string mypath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string mypath1 = @"\Roaming\Mozilla\Firefox\Profiles\";
string mypath2 = //here is where i would like to scan the \Roaming\Mozilla\Firefox\Profiles\ and store the folder inside as a string
string all_path = mypath + mypath1 + mypath2;
我相信这个示例将向您展示如何做您想要做的事情,它包括解析和导航子目录,包括获取您想要的子目录名称

具体而言,该行:

string [] directories = Directory.GetDirectories(mpath1 + mypath2)

我真的不明白你的问题。您不想在Firefox\Profiles下获取文件夹的名称并存储其绝对路径吗?