此代码正确获取selected_paths中指定的目录的内容,但前提是该目录为"C:".如果目录是"D:",则此代码将迭代我的应用程序的根目录(源文件所在的目录 - "D:\ excercizes\QT_projects\my_app").这是怎么回事?
QStringList my_app::extract_files_from_paths_(const QStringList& selected_paths)const
{
boost::filesystem3::path path;
QStringList result;
for (auto e : selected_paths)
{
boost::filesystem3::path path(e.toStdString().c_str());
if (boost::filesystem3::is_regular_file(path))
{
result.append(e);
}
else if (boost::filesystem3::is_directory(path) && !boost::filesystem3::is_empty(path))
{
std::vector<boost::filesystem3::path> paths_;
/*add everything from this path*/
std::copy(boost::filesystem3::directory_iterator(path), boost::filesystem3::directory_iterator(), // directory_iterator::value_type
std::back_inserter(paths_));
QStringList list_of_files;
for(auto e : paths_)
{
list_of_files.append(QString(e.string().c_str()));
}
return extract_files_from_paths_(list_of_files);
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
D:而D:\在Windows上两回事.
D:\指定D驱动器的根目录D:指定驱动器上的当前目录D每个驱动器存储一个当前目录(每个进程).所以它不是一个boostbug,它是一个Windows功能.
在cmdshell中,您可以看到驱动器的当前目录(例如):
cd d:
Run Code Online (Sandbox Code Playgroud)
您可以通过指定路径来更改它:
cd d:\home
Run Code Online (Sandbox Code Playgroud)
(请注意,如果您不在,则不会更改当前的工作目录D.)
cd /d d:并且cd /d d:\将分别更改shell的工作目录的当前目录D,并根D.
这不是一个错误.C:解析到驱动器上的当前目录C,这恰好是C:\.D:解析到驱动器上的当前目录D,这恰好是D:\excercizes\QT_projects\my_app.您应该写入D:\列出驱动器根目录中的文件D.
| 归档时间: |
|
| 查看次数: |
443 次 |
| 最近记录: |