- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qdir.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QDIR_H
    00043 #define QDIR_H
    00044
    00045 #include <QtCore/qstring.h>
    00046 #include <QtCore/qfileinfo.h>
    00047 #include <QtCore/qstringlist.h>
    00048 #include <QtCore/qshareddata.h>
    00049
    00050 QT_BEGIN_HEADER
    00051
    00052 QT_BEGIN_NAMESPACE
    00053
    00054 QT_MODULE(Core)
    00055
    00056 class QDirPrivate;
    00057
    00058 class Q_CORE_EXPORT QDir
    00059 {
    00060 protected:
    00061     QSharedDataPointer<QDirPrivate> d_ptr;
    00062
    00063 public:
    00064     enum Filter { Dirs        = 0x001,
    00065                   Files       = 0x002,
    00066                   Drives      = 0x004,
    00067                   NoSymLinks  = 0x008,
    00068                   AllEntries  = Dirs | Files | Drives,
    00069                   TypeMask    = 0x00f,
    00070 #ifdef QT3_SUPPORT
    00071                   All         = AllEntries,
    00072 #endif
    00073
    00074                   Readable    = 0x010,
    00075                   Writable    = 0x020,
    00076                   Executable  = 0x040,
    00077                   PermissionMask    = 0x070,
    00078 #ifdef QT3_SUPPORT
    00079                   RWEMask     = 0x070,
    00080 #endif
    00081
    00082                   Modified    = 0x080,
    00083                   Hidden      = 0x100,
    00084                   System      = 0x200,
    00085
    00086                   AccessMask  = 0x3F0,
    00087
    00088                   AllDirs       = 0x400,
    00089                   CaseSensitive = 0x800,
    00090                   NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
    00091                   NoDot         = 0x2000,
    00092                   NoDotDot      = 0x4000,
    00093
    00094                   NoFilter = -1
    00095 #ifdef QT3_SUPPORT
    00096                   ,DefaultFilter = NoFilter
    00097 #endif
    00098     };
    00099     Q_DECLARE_FLAGS(Filters, Filter)
    00100 #ifdef QT3_SUPPORT
    00101     typedef Filters FilterSpec;
    00102 #endif
    00103
    00104     enum SortFlag { Name        = 0x00,
    00105                     Time        = 0x01,
    00106                     Size        = 0x02,
    00107                     Unsorted    = 0x03,
    00108                     SortByMask  = 0x03,
    00109
    00110                     DirsFirst   = 0x04,
    00111                     Reversed    = 0x08,
    00112                     IgnoreCase  = 0x10,
    00113                     DirsLast    = 0x20,
    00114                     LocaleAware = 0x40,
    00115                     Type        = 0x80,
    00116                     NoSort = -1
    00117 #ifdef QT3_SUPPORT
    00118                   ,DefaultSort = NoSort
    00119 #endif
    00120     };
    00121     Q_DECLARE_FLAGS(SortFlags, SortFlag)
    00122
    00123     QDir(const QDir &);
    00124     QDir(const QString &path = QString());
    00125     QDir(const QString &path, const QString &nameFilter,
    00126          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
    00127     ~QDir();
    00128
    00129     QDir &operator=(const QDir &);
    00130     QDir &operator=(const QString &path);
    00131
    00132     void setPath(const QString &path);
    00133     QString path() const;
    00134     QString absolutePath() const;
    00135     QString canonicalPath() const;
    00136
    00137     static void addResourceSearchPath(const QString &path);
    00138
    00139     static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
    00140     static void addSearchPath(const QString &prefix, const QString &path);
    00141     static QStringList searchPaths(const QString &prefix);
    00142
    00143     QString dirName() const;
    00144     QString filePath(const QString &fileName) const;
    00145     QString absoluteFilePath(const QString &fileName) const;
    00146     QString relativeFilePath(const QString &fileName) const;
    00147
    00148 #ifdef QT_DEPRECATED
    00149     QT_DEPRECATED static QString convertSeparators(const QString &pathName);
    00150 #endif
    00151     static QString toNativeSeparators(const QString &pathName);
    00152     static QString fromNativeSeparators(const QString &pathName);
    00153
    00154     bool cd(const QString &dirName);
    00155     bool cdUp();
    00156
    00157     QStringList nameFilters() const;
    00158     void setNameFilters(const QStringList &nameFilters);
    00159
    00160     Filters filter() const;
    00161     void setFilter(Filters filter);
    00162     SortFlags sorting() const;
    00163     void setSorting(SortFlags sort);
    00164
    00165     uint count() const;
    00166     QString operator[](int) const;
    00167
    00168     static QStringList nameFiltersFromString(const QString &nameFilter);
    00169
    00170     QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
    00171     QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
    00172                           SortFlags sort = NoSort) const;
    00173
    00174     QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
    00175     QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
    00176                                 SortFlags sort = NoSort) const;
    00177
    00178     bool mkdir(const QString &dirName) const;
    00179     bool rmdir(const QString &dirName) const;
    00180     bool mkpath(const QString &dirPath) const;
    00181     bool rmpath(const QString &dirPath) const;
    00182
    00183     bool isReadable() const;
    00184     bool exists() const;
    00185     bool isRoot() const;
    00186
    00187     static bool isRelativePath(const QString &path);
    00188     inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
    00189     bool isRelative() const;
    00190     inline bool isAbsolute() const { return !isRelative(); }
    00191     bool makeAbsolute();
    00192
    00193     bool operator==(const QDir &dir) const;
    00194     inline bool operator!=(const QDir &dir) const {  return !operator==(dir); }
    00195
    00196     bool remove(const QString &fileName);
    00197     bool rename(const QString &oldName, const QString &newName);
    00198     bool exists(const QString &name) const;
    00199
    00200     static QFileInfoList drives();
    00201
    00202     static QChar separator();
    00203
    00204     static bool setCurrent(const QString &path);
    00205     static inline QDir current() { return QDir(currentPath()); }
    00206     static QString currentPath();
    00207
    00208     static inline QDir home() { return QDir(homePath()); }
    00209     static QString homePath();
    00210     static inline QDir root() { return QDir(rootPath()); }
    00211     static QString rootPath();
    00212     static inline QDir temp() { return QDir(tempPath()); }
    00213     static QString tempPath();
    00214
    00215 #ifndef QT_NO_REGEXP
    00216     static bool match(const QStringList &filters, const QString &fileName);
    00217     static bool match(const QString &filter, const QString &fileName);
    00218 #endif
    00219
    00220     static QString cleanPath(const QString &path);
    00221     void refresh() const;
    00222
    00223 #ifdef QT3_SUPPORT
    00224     typedef SortFlags SortSpec;
    00225     inline QT3_SUPPORT QString absPath() const { return absolutePath(); }
    00226     inline QT3_SUPPORT QString absFilePath(const QString &fileName, bool acceptAbsPath = true) const
    00227        { Q_UNUSED(acceptAbsPath); return absoluteFilePath(fileName); }
    00228     QT3_SUPPORT bool matchAllDirs() const;
    00229     QT3_SUPPORT void setMatchAllDirs(bool on);
    00230     inline QT3_SUPPORT QStringList entryList(const QString &nameFilter, Filters filters = NoFilter,
    00231                                            SortFlags sort = NoSort) const
    00232     { return entryList(nameFiltersFromString(nameFilter), filters, sort); }
    00233     inline QT3_SUPPORT QFileInfoList entryInfoList(const QString &nameFilter,
    00234                                                  Filters filters = NoFilter,
    00235                                                  SortFlags sort = NoSort) const
    00236     { return entryInfoList(nameFiltersFromString(nameFilter), filters, sort); }
    00237
    00238     QT3_SUPPORT QString nameFilter() const;
    00239     QT3_SUPPORT void setNameFilter(const QString &nameFilter);
    00240
    00241     inline QT3_SUPPORT bool mkdir(const QString &dirName, bool acceptAbsPath) const
    00242         { Q_UNUSED(acceptAbsPath); return mkdir(dirName); }
    00243     inline QT3_SUPPORT bool rmdir(const QString &dirName, bool acceptAbsPath) const
    00244         { Q_UNUSED(acceptAbsPath); return rmdir(dirName); }
    00245
    00246     inline QT3_SUPPORT void convertToAbs() { makeAbsolute(); }
    00247     inline QT3_SUPPORT static QString currentDirPath() { return currentPath(); }
    00248     inline QT3_SUPPORT static QString homeDirPath() { return homePath(); }
    00249     inline QT3_SUPPORT static QString rootDirPath() { return rootPath(); }
    00250     inline QT3_SUPPORT static QString cleanDirPath(const QString &name) { return cleanPath(name); }
    00251 #endif // QT3_SUPPORT
    00252 };
    00253
    00254 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
    00255 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)
    00256
    00257 #ifndef QT_NO_DEBUG_STREAM
    00258 class QDebug;
    00259 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters);
    00260 Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QDir &dir);
    00261 #endif
    00262
    00263 QT_END_NAMESPACE
    00264
    00265 QT_END_HEADER
    00266
    00267 #endif // QDIR_H