여러 하위 디렉토리가있는 디렉토리를 실행 중입니다. recursive_directory_iterator를 사용하고 있습니다. 나는 디렉터리 asr-> 콜렉션 -> (여러 디렉토리 및 텍스트 파일 몇 가지)VS2012의 is_directory()가 짝수 디렉토리의 경우 false를 반환합니다.
#include <iostream>
#include <filesystem>
#include <conio.h>
using namespace std::tr2::sys;
int main() {
std::string path_;
std::cout << " Enter the path ";
std::cin >> path_;
auto dir_path = path(path_);
for (auto it = directory_iterator(dir_path); it != directory_iterator(); ++it)
{
const auto& file = it->path();
std::cout << " path : " << file << std::endl;
if (is_directory (status(it->path())))
std::cout << " It is a directory. " << std::endl;
else
std::cout << " It is not a directory. " << std::endl;
}
_getch();
return 0;
}
나는 이것을 일찍 게시했다. 어리석은 실수 였어, 내가 바꿨어. 그러나 그것은 여전히 부글 거리고 있습니다. 내가 가지고있는 문제는 is-directory가 모든 것에 대해 false를 반환한다는 것입니다. 잘못 사용하고 있습니다. 아래의 MSDN URL을 연결했습니다.
부스트를 설치하고 코드를 실행했습니다. 그것은 효과가있다! 소스
또한http://msdn.microsoft.com/en-us/library/hh874754.aspx
#include <iostream>
#include <boost\filesystem.hpp>
#include <conio.h>
using namespace boost::filesystem;
int main() {
std::string path_;
std::cout << " Enter the path ";
std::cin >> path_;
auto dir_path = path(path_);
for (auto it = directory_iterator(dir_path); it != directory_iterator(); ++it)
{
const auto& file = it->path();
std::cout << " path : " << file << std::endl;
if (is_directory (status(it->path())))
std::cout << " It is a directory. " << std::endl;
else
std::cout << " It is not a directory. " << std::endl;
}
_getch();
return 0;
}
부스트 , 나는 그것을 사용하는 방법을 무엇 무엇인지에 더 좋은 문서가 없기 때문에 부스트 파일 시스템 설명서, 이것에 대한 튜토리얼로 사용할 수 있습니다.
Boost 문서 [여기] (http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v2/doc/index.htm)는 VC++ 2012 및 2013에 적용 가능합니다. Boost 문서 [here] (http://www.boost.org/doc/libs/1_57_0/libs/filesystem/doc/index.htm)는 VC++ 2015에 적용 가능합니다 (Boost.Filesystem의 다른 버전입니다. .) – ildjarn