コード例 #1
0
ファイル: dirgrinder.cpp プロジェクト: szkrawcz/aInf
QMultiMap<QString,FileAttributes> ListFilesInDirectoryTest(QDir dir, bool Hash)
{
    extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
    qt_ntfs_permission_lookup++; // turn checking on
    QMultiMap<QString, FileAttributes> fileAttHashTable; //making hash table to store file attributes
    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    dir.setSorting(QDir::Name);
    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i)
    {
       QFileInfo fileInfo = list.at(i);
       if (fileInfo.isFile())
       {
           FileAttributes tempFileAttributes;
           QDateTime date = fileInfo.lastModified();
           QString lastModified = date.toString();

            tempFileAttributes.absoluteFilePath = fileInfo.absoluteFilePath();
            tempFileAttributes.fileName = fileInfo.fileName();
            tempFileAttributes.filePath= fileInfo.path();
            if (Hash) tempFileAttributes.md5Hash = GetFileMd5hash(fileInfo.absoluteFilePath());
            tempFileAttributes.lastModified  = fileInfo.lastModified();
            tempFileAttributes.lastRead = fileInfo.lastRead();
            tempFileAttributes.created = fileInfo.created();
            tempFileAttributes.isHidden =  fileInfo.isHidden();
            tempFileAttributes.size = fileInfo.size();
            tempFileAttributes.owner = fileInfo.owner();
            fileAttHashTable.insert(fileInfo.absoluteFilePath(),tempFileAttributes);
       }

    }
return fileAttHashTable;
}
コード例 #2
0
ファイル: qdiriterator.cpp プロジェクト: 3163504123/phantomjs
/*!
    \internal
 */
void QDirIteratorPrivate::checkAndPushDirectory(const QFileInfo &fileInfo)
{
    // If we're doing flat iteration, we're done.
    if (!(iteratorFlags & QDirIterator::Subdirectories))
        return;

    // Never follow non-directory entries
    if (!fileInfo.isDir())
        return;

    // Follow symlinks only when asked
    if (!(iteratorFlags & QDirIterator::FollowSymlinks) && fileInfo.isSymLink())
        return;

    // Never follow . and ..
    QString fileName = fileInfo.fileName();
    if (QLatin1String(".") == fileName || QLatin1String("..") == fileName)
        return;

    // No hidden directories unless requested
    if (!(filters & QDir::AllDirs) && !(filters & QDir::Hidden) && fileInfo.isHidden())
        return;

    // Stop link loops
    if (!visitedLinks.isEmpty() &&
        visitedLinks.contains(fileInfo.canonicalFilePath()))
        return;

    pushDirectory(fileInfo);
}
コード例 #3
0
/** \fn     ImageUtils::LoadFileData(QFileInfo &, DataMap *)
 *  \brief  Loads the information from the fileInfo into the dataMap object
 *  \param  fileInfo Holds the information about the file
 *  \param  data Holds the loaded information about a file
 *  \return void
 */
void ImageUtils::LoadFileData(QFileInfo &fileInfo,
                              ImageMetadata *data)
{
    data->m_fileName	= fileInfo.absoluteFilePath();
    data->m_name        = fileInfo.fileName();
    data->m_path        = fileInfo.path();
    data->m_modTime     = fileInfo.lastModified().toTime_t();
    data->m_size        = fileInfo.size();
    data->m_isHidden    = fileInfo.isHidden();
    data->m_extension   = fileInfo.completeSuffix().toLower();

    // Set defaults, the data will be loaded later
    data->SetAngle(0);
    data->m_date = MAX_UTCTIME;

    if (m_imageFileExt.contains(data->m_extension))
    {
        data->m_type = kImageFile;
    }
    else if (m_videoFileExt.contains(data->m_extension))
    {
        data->m_type = kVideoFile;
    }
    else
    {
        data->m_type = kUnknown;
    }
}
コード例 #4
0
FileInfo toFileInfo(const QFileInfo &info)
{
    FileInfo fi;

    fi.m_valid = true;
    fi.m_exists = info.exists();
    fi.m_permissions = info.permissions();
    fi.m_isSymlink = info.isSymLink();
    fi.m_type = FileInfo::System;
    fi.m_hidden = info.isHidden();
    fi.m_size = -1;
    fi.m_lastModified = info.lastModified();

    if (info.isDir())
        fi.m_type = FileInfo::Dir;
    else if (info.isFile())
        fi.m_type = FileInfo::File;
    else if (!info.exists() && info.isSymLink())
        fi.m_type = FileInfo::System;

    if (fi.type() == FileInfo::Dir)
        fi.m_size = 0;
    else if (fi.type() == FileInfo::File)
        fi.m_size = info.size();
    if (!info.exists() && !info.isSymLink())
        fi.m_size = -1;

    return fi;
}
コード例 #5
0
QString FilteredDirIterator::next()
{
    if (m_firstItem) {
        m_firstItem = false;
        m_filePath = m_currentIter->path();
        return m_filePath;
    }

    m_filePath.clear();
    if (!m_currentIter) {
        return QString();
    }

    while (!m_currentIter->hasNext()) {
        delete m_currentIter;
        m_currentIter = nullptr;

        if (!m_paths.isEmpty()) {
            const QString path = m_paths.pop();
            m_currentIter = new QDirIterator(path, m_filters);
        } else {
            return QString();
        }
    }

    m_filePath = m_currentIter->next();
    const QFileInfo info = m_currentIter->fileInfo();

    if (info.isDir()) {
        if (shouldIndexFolder(m_filePath)) {
            m_paths.push(m_filePath);
            return m_filePath;
        } else {
            return next();
        }
    }
    else if (info.isFile()) {
        bool shouldIndexHidden = false;
        if (m_config)
            shouldIndexHidden = m_config->indexHiddenFilesAndFolders();

        bool shouldIndexFile = (!info.isHidden() || shouldIndexHidden)
                               && (!m_config || m_config->shouldFileBeIndexed(info.fileName()));
        if (shouldIndexFile) {
            return m_filePath;
        } else {
            return next();
        }
    }
    else {
        return next();
    }
}
コード例 #6
0
/*! Recursively delete a directory and its items.
*/
void QwsClientSocket::deleteDirRecursive(QString pathToDir)
{    
    QDirIterator it(pathToDir,
                    QDir::NoDotAndDotDot | QDir::AllEntries,
                    QDirIterator::Subdirectories);
    while (it.hasNext()) {
        QString itemPath = it.next();
        QFileInfo itemInfo = it.fileInfo();
        if (itemInfo.isHidden()) { continue; }
        if (itemInfo.isDir()) {
            qDebug() << "Deleting recurse dir:" << itemInfo.absoluteFilePath();
            deleteDirRecursive(itemInfo.absoluteFilePath());
        } else if (itemInfo.isFile()) {
            qDebug() << "Deleting file:" << itemInfo.absoluteFilePath();
            QFile(itemInfo.absoluteFilePath()).remove();
        }
    }

    QDir().rmdir(pathToDir);
}
コード例 #7
0
/** \fn     ImageUtils::LoadDirectoryData(QFileInfo &, DataMap *, int)
 *  \brief  Loads the information from the fileInfo into the dataMap object
 *  \param  fileInfo Holds the information about the file
 *  \param  data Holds the loaded information about a file
 *  \param  parentId The parent directory
 *  \return void
 */
void ImageUtils::LoadDirectoryData(QFileInfo &fileInfo,
                                   ImageMetadata *data,
                                   int parentId)
{
    data->m_parentId    = parentId;
    data->m_fileName	= fileInfo.absoluteFilePath();
    data->m_name        = fileInfo.fileName();
    data->m_path        = fileInfo.path();
    data->m_isHidden    = fileInfo.isHidden();

    QDir dir(data->m_fileName);
    data->m_dirCount = dir.entryList(QDir::Dirs |
                                     QDir::NoSymLinks |
                                     QDir::NoDotAndDotDot |
                                     QDir::Readable).count();

    data->m_fileCount = dir.entryList(QDir::Files |
                                      QDir::NoSymLinks |
                                      QDir::NoDotAndDotDot |
                                      QDir::Readable).count();
}
コード例 #8
0
ファイル: utility.cpp プロジェクト: 151706061/QQStars
bool myRemovePath(QString dirPath, bool deleteHidden, bool deleteSelf)
{
    qDebug()<<"removePath的进程"<<QThread::currentThread ();
    QDir entry (dirPath);
    if(!entry.exists()||!entry.isReadable())
        return false;
    entry.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden);
    QFileInfoList dirList = entry.entryInfoList();
    bool bHaveHiddenFile = false;

    if(!dirList.isEmpty()) {
        for( int i = 0; i < dirList.size() ; ++i) {
            QFileInfo info = dirList.at(i);
            if(info.isHidden() && !deleteHidden) {
                bHaveHiddenFile = true;
                continue;
            }
            QString path = info.absoluteFilePath();
            if(info.isDir()) {
                if(!myRemovePath(path, deleteHidden, true))
                    return false;
            }else if(info.isFile()) {
                if(!QFile::remove(path))
                    return false;
            }else
                return false;
        }
    }

    if(deleteSelf && !bHaveHiddenFile) {
        if(!entry.rmdir(dirPath)) {
            return false;
        }
    }
    return true;
}
コード例 #9
0
ファイル: qdiriterator.cpp プロジェクト: 3163504123/phantomjs
bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInfo &fi) const
{
    Q_ASSERT(!fileName.isEmpty());

    // filter . and ..?
    const int fileNameSize = fileName.size();
    const bool dotOrDotDot = fileName[0] == QLatin1Char('.')
                             && ((fileNameSize == 1)
                                 ||(fileNameSize == 2 && fileName[1] == QLatin1Char('.')));
    if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1)
        return false;
    if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2)
        return false;

    // name filter
#ifndef QT_NO_REGEXP
    // Pass all entries through name filters, except dirs if the AllDirs
    if (!nameFilters.isEmpty() && !((filters & QDir::AllDirs) && fi.isDir())) {
        bool matched = false;
        for (QVector<QRegExp>::const_iterator iter = nameRegExps.constBegin(),
                                              end = nameRegExps.constEnd();
                iter != end; ++iter) {

            QRegExp copy = *iter;
            if (copy.exactMatch(fileName)) {
                matched = true;
                break;
            }
        }
        if (!matched)
            return false;
    }
#endif
    // skip symlinks
    const bool skipSymlinks = (filters & QDir::NoSymLinks);
    const bool includeSystem = (filters & QDir::System);
    if(skipSymlinks && fi.isSymLink()) {
        // The only reason to save this file is if it is a broken link and we are requesting system files.
        if(!includeSystem || fi.exists())
            return false;
    }

    // filter hidden
    const bool includeHidden = (filters & QDir::Hidden);
    if (!includeHidden && !dotOrDotDot && fi.isHidden())
        return false;

    // filter system files
    if (!includeSystem && (!(fi.isFile() || fi.isDir() || fi.isSymLink())
                    || (!fi.exists() && fi.isSymLink())))
        return false;

    // skip directories
    const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
    if (skipDirs && fi.isDir())
        return false;

    // skip files
    const bool skipFiles    = !(filters & QDir::Files);
    if (skipFiles && fi.isFile())
        // Basically we need a reason not to exclude this file otherwise we just eliminate it.
        return false;

    // filter permissions
    const bool filterPermissions = ((filters & QDir::PermissionMask)
                                    && (filters & QDir::PermissionMask) != QDir::PermissionMask);
    const bool doWritable = !filterPermissions || (filters & QDir::Writable);
    const bool doExecutable = !filterPermissions || (filters & QDir::Executable);
    const bool doReadable = !filterPermissions || (filters & QDir::Readable);
    if (filterPermissions
        && ((doReadable && !fi.isReadable())
            || (doWritable && !fi.isWritable())
            || (doExecutable && !fi.isExecutable()))) {
        return false;
    }

    return true;
}
コード例 #10
0
ファイル: qdiriterator.cpp プロジェクト: Fale/qtmoko
/*!
    \internal

    This convenience function implements the iterator's filtering logics and
    applies then to the current directory entry.

    It returns true if the current entry matches the filters (i.e., the
    current entry will be returned as part of the directory iteration);
    otherwise, false is returned.
*/
bool QDirIteratorPrivate::matchesFilters(const QAbstractFileEngineIterator *it) const
{
    const bool filterPermissions = ((filters & QDir::PermissionMask)
                                    && (filters & QDir::PermissionMask) != QDir::PermissionMask);
    const bool skipDirs     = !(filters & (QDir::Dirs | QDir::AllDirs));
    const bool skipFiles    = !(filters & QDir::Files);
    const bool skipSymlinks = (filters & QDir::NoSymLinks);
    const bool doReadable   = !filterPermissions || (filters & QDir::Readable);
    const bool doWritable   = !filterPermissions || (filters & QDir::Writable);
    const bool doExecutable = !filterPermissions || (filters & QDir::Executable);
    const bool includeHidden = (filters & QDir::Hidden);
    const bool includeSystem = (filters & QDir::System);

#ifndef QT_NO_REGEXP
    // Prepare name filters
    QList<QRegExp> regexps;
    bool hasNameFilters = !nameFilters.isEmpty() && !(nameFilters.contains(QLatin1String("*")));
    if (hasNameFilters) {
        for (int i = 0; i < nameFilters.size(); ++i) {
            regexps << QRegExp(nameFilters.at(i),
                               (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive,
                               QRegExp::Wildcard);
        }
    }
#endif

    QString fileName = it->currentFileName();
    if (fileName.isEmpty()) {
        // invalid entry
        return false;
    }

    QFileInfo fi = it->currentFileInfo();
    QString filePath = it->currentFilePath();

#ifndef QT_NO_REGEXP
    // Pass all entries through name filters, except dirs if the AllDirs
    // filter is passed.
    if (hasNameFilters && !((filters & QDir::AllDirs) && fi.isDir())) {
        bool matched = false;
        for (int i = 0; i < regexps.size(); ++i) {
            if (regexps.at(i).exactMatch(fileName)) {
                matched = true;
                break;
            }
        }
        if (!matched)
            return false;
    }
#endif
    
    bool dotOrDotDot = (fileName == QLatin1String(".") || fileName == QLatin1String(".."));
    if ((filters & QDir::NoDotAndDotDot) && dotOrDotDot)
        return false;

    bool isHidden = !dotOrDotDot && fi.isHidden();
    if (!includeHidden && isHidden)
        return false;

    bool isSystem = (!fi.isFile() && !fi.isDir() && !fi.isSymLink())
                    || (!fi.exists() && fi.isSymLink());
    if (!includeSystem && isSystem)
        return false;

    bool alwaysShow = (filters & QDir::TypeMask) == 0
        && ((isHidden && includeHidden)
            || (includeSystem && isSystem));

    // Skip files and directories
    if ((filters & QDir::AllDirs) == 0 && skipDirs && fi.isDir()) {
        if (!alwaysShow)
            return false;
    }

    if ((skipFiles && (fi.isFile() || !fi.exists()))
        || (skipSymlinks && fi.isSymLink())) {
        if (!alwaysShow)
            return false;
    }

    if (filterPermissions
        && ((doReadable && !fi.isReadable())
            || (doWritable && !fi.isWritable())
            || (doExecutable && !fi.isExecutable()))) {
        return false;
    }

    if (!includeSystem && !dotOrDotDot && ((fi.exists() && !fi.isFile() && !fi.isDir() && !fi.isSymLink())
                                           || (!fi.exists() && fi.isSymLink()))) {
        return false;
    }
    
    return true;
}