I have some code to list the files in a directory. For Windows Systems, I'm hoping to end up with a list of files and folders that matches what you'd see in Windows Explorer. For example, when I list C:\ on Server 2016, I want to have the Users
folder but not the Documents and Settings
junction. Currently I'm getting both, with no apparent way of differentiating between them.
My current code looks like this:
boost::filesystem::directory_iterator itr(dir);
boost::filesystem::directory_iterator end;
Poco::SharedPtr<Poco::JSON::Array> fileList(new Poco::JSON::Array);
for (; itr != end; ++itr) {
boost::filesystem::path entryPath = itr->path();
Poco::File file(entryPath.string());
// ...
I tried the Poco isLink()
method, but it returns false for junctions.
I also tried Poco::DirectoryIterator
, which gives the same behavior as Boost, and Poco::SortedDirectoryIterator
, which always throws File access error: sharing violation: \pagefile.sys
when reading C:\
.
Ideally, this code should include symlinks on Linux and MacOS systems, while ignoring junctions on Windows.