Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am in process of migrating my project code to the newer version of boost (1.62 from 1.38).

What i am experiencing is a general purpose class "wdirectory_iterator" is missing in the newer version. Is it deprecated ?? What is the alternative for it ?

What I have tried:

Tried searching for the documentation. But dint find anything.
Posted
Updated 19-Dec-17 2:04am

1 solution

It has been merged into the C++17 standard: std::filesystem::directory_iterator - cppreference.com[^].

If you still want to use the Boost implementation (and not compiling with C++17 support) you must use an older Boost version or check if it is still there but requires a definition to be enabled.
 
Share this answer
 
Comments
PrafullaVedante 19-Dec-17 8:13am    
Thanks for the comment. I have code like following.

boost::filesystem::wdirectory_iterator dirEndIter;
for(boost::filesystem::wdirectory_iterator iter(logParentDirectory); iter != dirEndIter; ++iter)
{
if(!boost::filesystem::is_regular_file(iter->status()))
{
continue;
}

std::tstring filePath = iter->string();

//I use this "filepath" for some further processing
.
.
.
.
.
}

How to convert it to suit newer boost implementation.
I am trying with following. Is it correct ?

boost::filesystem::directory_iterator dirEndIter;
for(boost::filesystem::directory_iterator iter(logParentDirectory); iter != dirEndIter; ++iter)
{
if(!boost::filesystem::is_regular_file(iter->status()))
{
continue;
}

std::tstring filePath = iter->path().generic_wstring();

//I use this "filepath" for some further processing
.
.
.
.
.
}
PrafullaVedante 19-Dec-17 8:15am    
Based on your comments i have made two changes in the code.

1)Changed wdirectory_iterator to directory_iterator

2)To retrieve wide char filepath from the iterator
i am using

iter->path().generic_wstring();

instead of

std::tstring filePath = iter->string();


Let me know if i am right.
Jochen Arndt 19-Dec-17 8:44am    
I can't answer that without knowing which STL implementation you are using (that is which compiler, which version, and which C++ version option is used). And even then I might not be able to check it if I don't have that compiler.

I assume Windows because other systems often use std::string with UTF-8 encoding. Then see https://docs.microsoft.com/en-us/cpp/standard-library/directory-iterator-class and https://docs.microsoft.com/en-us/cpp/standard-library/file-system-navigation.
PrafullaVedante 27-Dec-17 12:10pm    
I am using Visual Studio 2017.
Jochen Arndt 27-Dec-17 20:13pm    
The directory_iterator expects path class arguments. If you need conversion, you can explicitly create a path argument as shown in the examples of the two links from my previous comment.

With Windows, pathes (and the path class) are always UTF-16 (wstring).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900