Ejemplo n.º 1
0
void FileManager::findAllFiles(const std::string& pathToDirectory, bool iterateSubFolders)
{
    boost::filesystem::path dirPath_(pathToDirectory);

    if(boost::filesystem::exists(dirPath_) && boost::filesystem::is_directory(dirPath_))//check if the path exist and is a directory
    {
        if ( !exists( dirPath_ ) )
            std::cout << dirPath_.string() << " doesn't exist" << std::endl;

        boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end

        for ( boost::filesystem::directory_iterator itr( dirPath_ );
            itr != end_itr;
            ++itr )
        {
            //std::cout << "FOUND \t" <<itr->path().string() << std::endl;
        if ( is_directory(itr->status()))
        {
            if(iterateSubFolders)
                findAllFiles(itr->path().string(), iterateSubFolders);
        }
        else
            addToVector(*itr);
        }
    }
}
Ejemplo n.º 2
0
    std::vector<std::string> findAllFiles(const std::string& lookIn, const std::string& extension, bool deepSearch)
    {
        std::vector<std::string> ret;

        bool all = extension == "*";
        auto upExt = toUpper(extension);
        DIR *dir;
        struct dirent *ent;
        if ((dir = opendir(lookIn.c_str())) != NULL)
        {
            while ((ent = readdir(dir)) != NULL)
            {
                if (!strcmp(ent->d_name, "."))
                {
                    continue;
                }
                else if (!strcmp(ent->d_name, ".."))
                {
                    continue;
                }

                if (ent->d_type & DT_DIR)
                {
                    if (deepSearch)
                    {
                        auto ret2 = findAllFiles(lookIn + "/" + ent->d_name, extension, deepSearch);
                        ret.insert(ret.end(), ret2.begin(), ret2.end());
                    }
                }
                else
                {
                    if (all)
                    {
                        ret.push_back(lookIn + "/" + ent->d_name);
                    }
                    else if (toUpper(getExtension(ent->d_name)) == upExt)
                    {
                        ret.push_back(lookIn + "/" + ent->d_name);
                    }
                }
            }
            closedir(dir);
        }

        return std::move(ret);
    }
Ejemplo n.º 3
0
void LocalDiskRepo::findAllFiles(QString path, QStringList *found_files) const
{
    QCoreApplication::processEvents();
    QDir dir(path);
    dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
    dir.setSorting(QDir::Name);
    QStringList fileNames = dir.entryList();
    QString fileName;
    foreach(fileName, fileNames) {
        // .part is the extention for a file we are still writing
        // we dont wanna know about these files
        if (!fileName.endsWith(".part")) {
            found_files->append(relativeFilePath(path+'/'+fileName));
        }
    }

    // then recurse down into every directory

    dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
    QStringList dirs = dir.entryList();
    for (int i = 0; i < dirs.size(); ++i) {
        findAllFiles(path+"/"+dirs[i], found_files);
    }
}
Ejemplo n.º 4
0
QStringList LocalDiskRepo::readFilePaths() const
{
    QStringList found_files;
    findAllFiles(m_path, &found_files);
    return found_files;
}