【问题标题】:C# how to scan a folder and then store the scanned names as a stringC#如何扫描文件夹,然后将扫描的名称存储为字符串
【发布时间】:2015-10-24 20:00:43
【问题描述】:

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

这是我的代码:

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;

【问题讨论】:

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

标签: c# path directory


【解决方案1】:

我相信https://msdn.microsoft.com/en-us/library/c1sez4sc(v=vs.110).aspx 的示例将向您展示如何做您想做的事,它包括解析和导航子目录,包括获得您想要的名称。

具体是一行:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-04
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多