【发布时间】:2017-07-24 14:25:13
【问题描述】:
我想获取根目录下特定文件夹的位置。
例如,我有一个根目录C:\Dummy,我在这个文件夹中有一个子目录:
C:\Dummy\10\20\MyFolder
现在我想获取C:\Dummy目录下子目录MyFolder的路径。
我将编写一个函数来传递两个输入:
1)“根文件夹”即C:\Dummy
2)“子目录名称”即MyFolder。
String fun(string RootFolderPath, string subDirName)
{
//if any of the sub directories consists of `subDirName` then return the
//path
return subDirPath;
}
有什么方法可以实现吗?
请帮我解决这个问题。
【问题讨论】:
-
您期望得到什么?
10\20\MyFolder? -
@Kane,这就是我所期望的“C:\Dummy\10\20\MyFolder”。
-
所以你想要类似
std::string findDirectory(const std::string &root, const std::string &directory)的东西,它会在文件系统上找到相应的目录并返回它的路径?您能否更新您的问题,详细说明您有哪些输入数据以及您期望什么输出? -
@Kane,就像你提到的那样。我详细更新了我的问题。
-
谢谢,现在问题出在哪里更清楚了。请在下面查看 acraig5075 的答案。如果你想使用WinAPI,也许你会在这里找到答案:stackoverflow.com/questions/25639874/…。
标签: c++11 visual-c++