Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-07 08:48:09

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QDIR_H
0006 #define QDIR_H
0007 
0008 #include <QtCore/qcompare.h>
0009 #include <QtCore/qstring.h>
0010 #include <QtCore/qdirlisting.h>
0011 #include <QtCore/qfile.h>
0012 #include <QtCore/qfileinfo.h>
0013 #include <QtCore/qstringlist.h>
0014 #include <QtCore/qshareddata.h>
0015 
0016 QT_BEGIN_NAMESPACE
0017 
0018 class QDirIterator;
0019 class QDirPrivate;
0020 
0021 class Q_CORE_EXPORT QDir
0022 {
0023 public:
0024     enum Filter { Dirs        = 0x001,
0025                   Files       = 0x002,
0026                   Drives      = 0x004,
0027                   NoSymLinks  = 0x008,
0028                   AllEntries  = Dirs | Files | Drives,
0029                   TypeMask    = 0x00f,
0030 
0031                   Readable    = 0x010,
0032                   Writable    = 0x020,
0033                   Executable  = 0x040,
0034                   PermissionMask    = 0x070,
0035 
0036                   Modified    = 0x080,
0037                   Hidden      = 0x100,
0038                   System      = 0x200,
0039 
0040                   AccessMask  = 0x3F0,
0041 
0042                   AllDirs       = 0x400,
0043                   CaseSensitive = 0x800,
0044                   NoDot         = 0x2000,
0045                   NoDotDot      = 0x4000,
0046                   NoDotAndDotDot = NoDot | NoDotDot,
0047 
0048                   NoFilter = -1
0049     };
0050     Q_DECLARE_FLAGS(Filters, Filter)
0051 
0052     enum SortFlag { Name        = 0x00,
0053                     Time        = 0x01,
0054                     Size        = 0x02,
0055                     Unsorted    = 0x03,
0056                     SortByMask  = 0x03,
0057 
0058                     DirsFirst   = 0x04,
0059                     Reversed    = 0x08,
0060                     IgnoreCase  = 0x10,
0061                     DirsLast    = 0x20,
0062                     LocaleAware = 0x40,
0063                     Type        = 0x80,
0064                     NoSort = -1
0065     };
0066     Q_DECLARE_FLAGS(SortFlags, SortFlag)
0067 
0068     QDir(const QDir &);
0069     QDir(const QString &path = QString());
0070     QDir(const QString &path, const QString &nameFilter,
0071          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
0072 #ifdef Q_QDOC
0073     QDir(const std::filesystem::path &path);
0074     QDir(const std::filesystem::path &path, const QString &nameFilter,
0075          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
0076 #elif QT_CONFIG(cxx17_filesystem)
0077     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0078     QDir(const T &path) : QDir(QtPrivate::fromFilesystemPath(path))
0079     {
0080     }
0081     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0082     QDir(const T &path, const QString &nameFilter,
0083          SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries)
0084          : QDir(QtPrivate::fromFilesystemPath(path), nameFilter, sort, filter)
0085     {
0086     }
0087 #endif // QT_CONFIG(cxx17_filesystem)
0088     ~QDir();
0089 
0090     QDir &operator=(const QDir &);
0091     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDir)
0092 
0093     void swap(QDir &other) noexcept
0094     { d_ptr.swap(other.d_ptr); }
0095 
0096     void setPath(const QString &path);
0097 #ifdef Q_QDOC
0098     void setPath(const std::filesystem::path &path);
0099 #elif QT_CONFIG(cxx17_filesystem)
0100     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0101     void setPath(const T &path)
0102     {
0103         setPath(QtPrivate::fromFilesystemPath(path));
0104     }
0105 #endif // QT_CONFIG(cxx17_filesystem)
0106     QString path() const;
0107     QString absolutePath() const;
0108     QString canonicalPath() const;
0109 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0110     std::filesystem::path filesystemPath() const
0111     { return QtPrivate::toFilesystemPath(path()); }
0112     std::filesystem::path filesystemAbsolutePath() const
0113     { return QtPrivate::toFilesystemPath(absolutePath()); }
0114     std::filesystem::path filesystemCanonicalPath() const
0115     { return QtPrivate::toFilesystemPath(canonicalPath()); }
0116 #endif // QT_CONFIG(cxx17_filesystem)
0117 
0118 #ifndef QT_BOOTSTRAPPED
0119     static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
0120     static void addSearchPath(const QString &prefix, const QString &path);
0121 #ifdef Q_QDOC
0122     static void addSearchPath(const QString &prefix, const std::filesystem::path &path);
0123 #elif QT_CONFIG(cxx17_filesystem)
0124     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0125     static void addSearchPath(const QString &prefix, const T &path)
0126     {
0127         addSearchPath(prefix, QtPrivate::fromFilesystemPath(path));
0128     }
0129 #endif // QT_CONFIG(cxx17_filesystem)
0130     static QStringList searchPaths(const QString &prefix);
0131 #endif // QT_BOOTSTRAPPED
0132 
0133     QString dirName() const;
0134     QString filePath(const QString &fileName) const;
0135     QString absoluteFilePath(const QString &fileName) const;
0136     QString relativeFilePath(const QString &fileName) const;
0137 
0138     static QString toNativeSeparators(const QString &pathName);
0139     static QString fromNativeSeparators(const QString &pathName);
0140 
0141     bool cd(const QString &dirName);
0142     bool cdUp();
0143 
0144     QStringList nameFilters() const;
0145     void setNameFilters(const QStringList &nameFilters);
0146 
0147     Filters filter() const;
0148     void setFilter(Filters filter);
0149     SortFlags sorting() const;
0150     void setSorting(SortFlags sort);
0151 
0152 #if QT_CORE_REMOVED_SINCE(6, 5)
0153     uint count() const;
0154 #endif
0155     qsizetype count(QT6_DECL_NEW_OVERLOAD) const;
0156     bool isEmpty(Filters filters = Filters(AllEntries | NoDotAndDotDot)) const;
0157 
0158 #if QT_CORE_REMOVED_SINCE(6, 5) && QT_POINTER_SIZE != 4
0159     QString operator[](int) const;
0160 #endif
0161     QString operator[](qsizetype) const;
0162 
0163     static QStringList nameFiltersFromString(const QString &nameFilter);
0164 
0165     QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
0166     QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
0167                           SortFlags sort = NoSort) const;
0168 
0169     QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
0170     QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
0171                                 SortFlags sort = NoSort) const;
0172 
0173 #if QT_CORE_REMOVED_SINCE(6, 10)
0174     bool mkdir(const QString &dirName) const;
0175     bool mkdir(const QString &dirName, QFile::Permissions permissions) const;
0176 #endif
0177     bool mkdir(const QString &dirName, std::optional<QFile::Permissions> p = std::nullopt) const;
0178     bool rmdir(const QString &dirName) const;
0179 #if QT_CORE_REMOVED_SINCE(6, 10)
0180     bool mkpath(const QString &dirPath) const;
0181 #endif
0182     bool mkpath(const QString &dirPath, std::optional<QFile::Permissions> p = std::nullopt) const;
0183     bool rmpath(const QString &dirPath) const;
0184 
0185     bool removeRecursively();
0186 
0187     bool isReadable() const;
0188     bool exists() const;
0189     bool isRoot() const;
0190 
0191     static bool isRelativePath(const QString &path);
0192     inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
0193     bool isRelative() const;
0194     inline bool isAbsolute() const { return !isRelative(); }
0195     bool makeAbsolute();
0196 
0197 #if QT_CORE_REMOVED_SINCE(6, 8)
0198     bool operator==(const QDir &dir) const;
0199     inline bool operator!=(const QDir &dir) const { return !operator==(dir); }
0200 #endif
0201 
0202     bool remove(const QString &fileName);
0203     bool rename(const QString &oldName, const QString &newName);
0204     bool exists(const QString &name) const;
0205 
0206     static QFileInfoList drives();
0207 
0208     constexpr static inline QChar listSeparator() noexcept
0209     {
0210 #if defined(Q_OS_WIN)
0211         return u';';
0212 #else
0213         return u':';
0214 #endif
0215     }
0216 
0217     static QChar separator()
0218     {
0219 #if defined(Q_OS_WIN)
0220         return u'\\';
0221 #else
0222         return u'/';
0223 #endif
0224     }
0225 
0226     static bool setCurrent(const QString &path);
0227     static inline QDir current() { return QDir(currentPath()); }
0228     static QString currentPath();
0229 
0230     static inline QDir home() { return QDir(homePath()); }
0231     static QString homePath();
0232     static inline QDir root() { return QDir(rootPath()); }
0233     static QString rootPath();
0234     static inline QDir temp() { return QDir(tempPath()); }
0235     static QString tempPath();
0236 
0237 #if QT_CONFIG(regularexpression)
0238     static bool match(const QStringList &filters, const QString &fileName);
0239     static bool match(const QString &filter, const QString &fileName);
0240 #endif
0241 
0242     static QString cleanPath(const QString &path);
0243     void refresh() const;
0244 
0245 protected:
0246     explicit QDir(QDirPrivate &d);
0247 
0248     QSharedDataPointer<QDirPrivate> d_ptr;
0249 
0250 private:
0251     friend Q_CORE_EXPORT bool comparesEqual(const QDir &lhs, const QDir &rhs);
0252     Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QDir)
0253     friend class QDirIterator;
0254     friend class QDirListing;
0255     friend class QDirListingPrivate;
0256     // Q_DECLARE_PRIVATE equivalent for shared data pointers
0257     QDirPrivate *d_func();
0258     const QDirPrivate *d_func() const { return d_ptr.constData(); }
0259 };
0260 
0261 Q_DECLARE_SHARED(QDir)
0262 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
0263 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)
0264 
0265 #ifndef QT_NO_DEBUG_STREAM
0266 class QDebug;
0267 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters);
0268 Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QDir &dir);
0269 #endif
0270 
0271 QT_END_NAMESPACE
0272 
0273 #endif // QDIR_H