2012-12-14 1 views
0

여러 하위 디렉토리가있는 디렉토리를 실행 중입니다. 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; 
} 
부스트 , 나는 그것을 사용하는 방법을 무엇 무엇인지에 더 좋은 문서가 없기 때문에 부스트 파일 시스템 설명서, 이것에 대한 튜토리얼로 사용할 수 있습니다.

+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

답변

1

첫 번째 주요 업데이트로 Visual Studio를 업데이트하면 문제가 해결되었습니다.

2
if (is_directory (status(dir_path))) 

예, 잘못 사용하고 있습니다. dir_path가 아닌 파일을 테스트 해보십시오. dir_path가 디렉토리라는 것을 이미 알고 있습니다.

+0

if (is_directory (status) (file))로 변경했는데, else 블록이 디렉토리가 아니라는 것을 추가했습니다. 이제는 else 블록 만 호출됩니다. – ani

+0

부스트를 사용해 보았습니다. Microsoft 구현에서는 작동하지 않습니다. – ani

관련 문제