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