This code correctly gets contents of a directory specified in selected_paths but only if the directory is “C:”. If the directory is “D:” this code iterates over a root directory (the directory where the source files are located – “D:\excercizes\QT_projects\my_app”) of my app. What’s going on?
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;
}
D:andD:\are two different things on Windows.D:\designates the root of theDdriveD:designates the current directory on theDdriveOne current directory is stored per drive (per process). So it’s not a
boostbug, its a Windows feature.In a
cmdshell, you can see the current directory for a drive with (e.g.):You can change it by specifying a path:
(note that this will not change your current working directory if you’re not on
D.)cd /d d:andcd /d d:\will respectively change the shell’s working directory to the current directory ofD, and to the root ofD.