Yes, std::filesystem::directory_iterator
can be used with network paths. Network paths, also known as UNC (Universal Naming Convention) paths in Windows, can be iterated similarly to local file system paths.
To use a network path with std::filesystem::directory_iterator
, you need to provide the UNC path as a string to the iterator. Here’s an example:
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
int main() {
fs::directory_iterator start{
R"(\\server\share\directory)"};
fs::directory_iterator end{};
for (auto iter{start}; iter != end; ++iter) {
std::cout << iter->path().string() << '\n';
}
}
\\server\share\directory\file1.txt
\\server\share\directory\file2.txt
\\server\share\directory\subdirectory
Using std::filesystem::directory_iterator
with network paths is straightforward, but keep these considerations in mind to handle any potential issues effectively.
Answers to questions are automatically generated and may not have been reviewed.
An introduction to iterating through the file system, using directory iterators and recursive directory iterators