0

複数のサブディレクトリを含むディレクトリを実行しています。recursive_directory_iterator を使用しています。ディレクトリ asr->collections-> (複数のディレクトリといくつかのテキスト ファイル) があります。

#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 をリンクしました。

ブーストをインストールしてコードを実行しました。出来た !ブーストソース

#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;
}

http://msdn.microsoft.com/en-us/library/hh874754.aspx

また、ブーストファイルシステムのドキュメントをチュートリアルとして使用できますか?これは、何が何で、どのように使用するかについての適切なドキュメントがないためです。

4

2 に答える 2

2
if (is_directory (status(dir_path)) )

はい、使い方が間違っています。dir_path ではなく、ファイルをテストしてみてください。dir_path がディレクトリであることは既にご存じでしょう。

于 2012-12-14T12:48:55.183 に答える
1

わかりました。最初のメジャーアップデートでVisualStudioをアップデートした後、問題は修正されました。

于 2012-12-16T06:01:02.297 に答える