⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdir.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    Q_D(const QDir);    d->updateFileLists();    return d->data->files.count();}/*!    Returns the file name at position \a pos in the list of file    names. Equivalent to entryList().at(index).    Returns an empty string if \a pos is out of range or if the    entryList() function failed.    \sa count(), entryList()*/QString QDir::operator[](int pos) const{    Q_D(const QDir);    d->updateFileLists();    return d->data->files[pos];}/*!    \overload    Returns a list of the names of all the files and directories in    the directory, ordered in accordance with setSorting() and    filtered in accordance with setFilter() and setNameFilters().    The filter and sorting specifications can be overridden using the    \a filters and \a sort arguments.    Returns an empty list if the directory is unreadable or does not    exist or if nothing matches the specification.    \sa entryInfoList(), setNameFilters(), setSorting(), setFilter()*/QStringList QDir::entryList(Filters filters, SortFlags sort) const{    Q_D(const QDir);    return entryList(d->data->nameFilters, filters, sort);}/*!    \overload    Returns a list of QFileInfo objects for all the files and    directories in the directory, ordered in accordance with    setSorting() and filtered in accordance with setFilter() and    setNameFilters().    The filter and sorting specifications can be overridden using the    \a filters and \a sort arguments.    Returns an empty list if the directory is unreadable or does not    exist or if nothing matches the specification.    \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()*/QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const{    Q_D(const QDir);    return entryInfoList(d->data->nameFilters, filters, sort);}/*!    Returns a list of the names of all the files and directories in    the directory, ordered in accordance with setSorting() and    filtered in accordance with setFilter() and setNameFilters().    The name filter, file attributes filter, and the sorting    specifications can be overridden using the \a nameFilters, \a    filters and \a sort arguments.    Returns an empty list if the directory is unreadable or does not    exist or if nothing matches the specification.    \sa entryInfoList(), setNameFilters(), setSorting(), setFilter()*/QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,                            SortFlags sort) const{    Q_D(const QDir);    if (filters == NoFilter)        filters = d->data->filters;#ifdef QT3_SUPPORT    if (d->matchAllDirs)        filters |= AllDirs;#endif    if (sort == NoSort)        sort = d->data->sort;    if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) {        d->updateFileLists();        return d->data->files;    }    QStringList l = d->data->fileEngine->entryList(filters, nameFilters);    QStringList ret;    d->sortFileList(sort, l, &ret, 0);    return ret;}/*!    Returns a list of QFileInfo objects for all the files and    directories in the directory, ordered in accordance with    setSorting() and filtered in accordance with setFilter() and    setNameFilters().    The name filter, file attributes filter, and sorting    specifications can be overridden using the \a nameFilters, \a    filters, and \a sort arguments.    Returns an empty list if the directory is unreadable or does not    exist or if nothing matches the specification.    \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()*/QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters,                                  SortFlags sort) const{    Q_D(const QDir);    if (filters == NoFilter)        filters = d->data->filters;#ifdef QT3_SUPPORT    if (d->matchAllDirs)        filters |= AllDirs;#endif    if (sort == NoSort)        sort = d->data->sort;    if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) {        d->updateFileLists();        return d->data->fileInfos;    }    QFileInfoList ret;    QStringList l = d->data->fileEngine->entryList(filters, nameFilters);    d->sortFileList(sort, l, 0, &ret);    return ret;}/*!    Creates a sub-directory called \a dirName.    Returns true on success; otherwise returns false.    \sa rmdir()*/bool QDir::mkdir(const QString &dirName) const{    Q_D(const QDir);    if (dirName.isEmpty()) {        qWarning("QDir::mkdir: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirName);    return d->data->fileEngine->mkdir(fn, false);}/*!    Removes the directory specified by \a dirName.    The directory must be empty for rmdir() to succeed.    Returns true if successful; otherwise returns false.    \sa mkdir()*/bool QDir::rmdir(const QString &dirName) const{    Q_D(const QDir);    if (dirName.isEmpty()) {        qWarning("QDir::rmdir: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirName);    return d->data->fileEngine->rmdir(fn, false);}/*!    Creates the directory path \a dirPath.    The function will create all parent directories necessary to    create the directory.    Returns true if successful; otherwise returns false.    \sa rmpath()*/bool QDir::mkpath(const QString &dirPath) const{    Q_D(const QDir);    if (dirPath.isEmpty()) {        qWarning("QDir::mkpath: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirPath);    return d->data->fileEngine->mkdir(fn, true);}/*!    Removes the directory path \a dirPath.    The function will remove all parent directories in \a dirPath,    provided that they are empty. This is the opposite of    mkpath(dirPath).    Returns true if successful; otherwise returns false.    \sa mkpath()*/bool QDir::rmpath(const QString &dirPath) const{    Q_D(const QDir);    if (dirPath.isEmpty()) {        qWarning("QDir::rmpath: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirPath);    return d->data->fileEngine->rmdir(fn, true);}/*!    Returns true if the directory is readable \e and we can open files    by name; otherwise returns false.    \warning A false value from this function is not a guarantee that    files in the directory are not accessible.    \sa QFileInfo::isReadable()*/bool QDir::isReadable() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return false;    const QAbstractFileEngine::FileFlags info = d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType                                                                       |QAbstractFileEngine::PermsMask);    if(!(info & QAbstractFileEngine::DirectoryType))        return false;    return info & QAbstractFileEngine::ReadUserPerm;}/*!    \overload    Returns true if the \e directory exists; otherwise returns false.    (If a file with the same name is found this function will return    false).    \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return false;    const QAbstractFileEngine::FileFlags info = d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType                                                                       |QAbstractFileEngine::ExistsFlag);    if(!(info & QAbstractFileEngine::DirectoryType))        return false;    return info & QAbstractFileEngine::ExistsFlag;}/*!    Returns true if the directory is the root directory; otherwise    returns false.    Note: If the directory is a symbolic link to the root directory    this function returns false. If you want to test for this use    canonicalPath(), e.g.    \code        QDir dir("/tmp/root_link");        dir = dir.canonicalPath();        if (dir.isRoot())            qWarning("It is a root link");    \endcode    \sa root(), rootPath()*/bool QDir::isRoot() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return true;    return d->data->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;}/*!    \fn bool QDir::isAbsolute() const    Returns true if the directory's path is absolute; otherwise    returns false. See isAbsolutePath().    \sa isRelative() makeAbsolute() cleanPath()*//*!   \fn bool QDir::isAbsolutePath(const QString &)    Returns true if \a path is absolute; returns false if it is    relative.    \sa isAbsolute() isRelativePath() makeAbsolute() cleanPath()*//*!    Returns true if the directory path is relative; otherwise returns    false. (Under Unix a path is relative if it does not start with a    "/").    \sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath()*/bool QDir::isRelative() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return false;    return d->data->fileEngine->isRelativePath();}/*!    Converts the directory path to an absolute path. If it is already    absolute nothing happens. Returns true if the conversion    succeeded; otherwise returns false.    \sa isAbsolute() isAbsolutePath() isRelative() cleanPath()*/bool QDir::makeAbsolute() // ### What do the return values signify?{    Q_D(QDir);    if(!d->data->fileEngine)        return false;    QString absolutePath = d->data->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);    if(QDir::isRelativePath(absolutePath))        return false;    d->detach();    d->data->path = absolutePath;    d->data->fileEngine->setFileName(absolutePath);    if(!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType))        return false;    return true;}/*!    Returns true if directory \a dir and this directory have the same    path and their sort and filter settings are the same; otherwise    returns false.    Example:    \code        // The current directory is "/usr/local"        QDir d1("/usr/local/bin");        QDir d2("bin");        if (d1 == d2)            qDebug("They're the same");    \endcode*/bool QDir::operator==(const QDir &dir) const{    const QDirPrivate *d = d_func();    const QDirPrivate *other = dir.d_func();    if(d->data == other->data)        return true;    Q_ASSERT(d->data->fileEngine && other->data->fileEngine);    if(d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive())        return false;    if(d->data->filters == other->data->filters       && d->data->sort == other->data->sort       && d->data->nameFilters == other->data->nameFilters) {        QString dir1 = absolutePath(), dir2 = dir.absolutePath();        if(!other->data->fileEngine->caseSensitive())            return (dir1.toLower() == dir2.toLower());        return (dir1 == dir2);    }    return false;}/*!    Makes a copy of the \a dir object and assigns it to this QDir    object.*/QDir &QDir::operator=(const QDir &dir){    if (this == &dir)        return *this;    Q_D(QDir);    qAtomicAssign(d->data, dir.d_func()->data);    return *this;}/*!    \overload    \obsolete    Sets the directory path to the given \a path.    Use setPath() instead.*/QDir &QDir::operator=(const QString &path){    Q_D(QDir);    d->setPath(path);    return *this;}/*!    \fn bool QDir::operator!=(const QDir &dir) const    Returns true if directory \a dir and this directory have different    paths or different sort or filter settings; otherwise returns    false.    Example:    \code        // The current directory is "/usr/local"        QDir d1("/usr/local/bin");        QDir d2("bin");        if (d1 != d2)            qDebug("They differ");    \endcode*//*!    Removes the file, \a fileName.    Returns true if the file is removed successfully; otherwise    returns false.*/bool QDir::remove(const QString &fileName){    if (fileName.isEmpty()) {        qWarning("QDir::remove: Empty or null file name");        return false;    }    QString p = filePath(fileName);    return QFile::remove(p);}/*!    Renames a file or directory from \a oldName to \a newName, and returns    true if successful; otherwise returns false.    On most file systems, rename() fails only if \a oldName does not    exist, if \a newName and \a oldName are not on the same    partition or if a file with the new name already exists.    However, there are also other reasons why rename() can    fail. For example, on at least one file system rename() fails if    \a newName points to an open file.*/bool QDir::rename(const QString &oldName, const QString &newName){    Q_D(QDir);    if (oldName.isEmpty() || newName.isEmpty()) {        qWarning("QDir::rename: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QFile file(filePath(oldName));    if(!file.exists())        return false;    return file.rename(filePath(newName));}/*!    Returns true if the file called \a name exists; otherwise returns    false.    \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists(const QString &name) const{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -