4#include "qplatformdefs.h"
9#ifndef QT_NO_DEBUG_STREAM
15#if QT_CONFIG(regularexpression)
24#ifndef QT_BOOTSTRAPPED
43 char c =
path.at(0).toLatin1();
44 if ((
c <
'a' ||
c >
'z') && (
c <
'A' ||
c >
'Z'))
46 if (
path.at(1).toLatin1() !=
':')
48 return path.mid(0, 2);
65 if (allowUncPaths &&
name.startsWith(
"//"_L1)) {
68 return nextSlash >= 0 ? nextSlash + 1 :
len;
71 if (
len >= 2 &&
name.at(1) == u
':') {
73 return len > 2 &&
name.at(2) == u
'/' ? 3 : 2;
76 if (
name.at(0) == u
'/')
83 QDir::SortFlags sort_, QDir::Filters filters_)
88 auto isEmpty = [](
const auto &e) {
return e.isEmpty(); };
97 nameFilters(
copy.nameFilters),
101 dirEntry(
copy.dirEntry)
121 const QAbstractFileEngine::FileFlags
info =
135 if (
i == -1 && nameFilter.
indexOf(u
' ', 0) != -1)
147 ret.append(e.trimmed().toString());
157 && (!(
p.length() == 3 &&
p.at(1).unicode() ==
':' &&
p.at(0).isLetter()))
160 p.truncate(
p.size() - 1);
187 auto absoluteFileSystemEntry =
190 return absoluteFileSystemEntry.
filePath();
214 QDir::SortFlags qt_cmp_si_sort_flags;
216#ifndef QT_BOOTSTRAPPED
220#ifndef QT_BOOTSTRAPPED
222 : qt_cmp_si_sort_flags(
flags), collator(coll)
231 : qt_cmp_si_sort_flags(
flags)
239#ifndef QT_BOOTSTRAPPED
243 return a.compare(
b, cs);
252 if ((qt_cmp_si_sort_flags &
QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir()))
254 if ((qt_cmp_si_sort_flags &
QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir()))
255 return !f1->item.isDir();
268 r = firstModified.
msecsTo(secondModified);
272 r = f2->item.size() - f1->item.size();
284 if (f1->filename_cache.isNull())
285 f1->filename_cache = f1->item.fileName();
286 if (f2->filename_cache.isNull())
287 f2->filename_cache = f2->item.fileName();
316 QVarLengthArray<QDirSortItem, 64> si;
319 si.emplace_back(l.
at(
i),
sort);
321#ifndef QT_BOOTSTRAPPED
334 auto &fileInfo = si[
i].item;
338 const bool cached = !si[
i].filename_cache.isNull();
339 names->append(cached ? si[
i].filename_cache : fileInfo.fileName());
598 SortFlags sort, Filters
filters)
656 return d->dirEntry.filePath();
671 return d->resolveAbsoluteEntry();
695 if (!
d->fileEngine) {
699 return answer.filePath();
719 return d->dirEntry.fileName();
730 if (
size > 1 &&
path.at(1).unicode() ==
':') {
733 }
else if (
path.startsWith(
"//"_L1)) {
736 for (
int i = 0 ;
i < 2 ; ++
i) {
737 while (drive <
size &&
path.at(drive).unicode() ==
'/')
740 qWarning(
"Base directory starts with neither a drive nor a UNC share: %s",
744 while (drive <
size &&
path.at(drive).unicode() !=
'/')
796 if (
ret.isEmpty() ||
ret.endsWith(u
'/'))
815 QString absoluteDirPath =
d->resolveAbsoluteEntry();
817 return absoluteDirPath;
822 const qsizetype drive = drivePrefixLength(absoluteDirPath);
826 qWarning(
"Base directory's drive is not a letter: %s",
831 if (!absoluteDirPath.endsWith(u
'/'))
832 return absoluteDirPath % u
'/' %
fileName;
855 bool fileDriveMissing =
false;
856 if (fileDrive.isEmpty()) {
857 fileDrive = dirDrive;
858 fileDriveMissing =
true;
861 if (fileDrive.toLower() != dirDrive.toLower()
862 || (
file.startsWith(
"//"_L1)
868 if (!fileDriveMissing)
876 const auto dend = dirElts.end();
877 const auto fend = fileElts.end();
878 auto dit = dirElts.begin();
879 auto fit = fileElts.begin();
891 while (dit != dend && fit != fend && eq(*dit, *fit)) {
896 while (dit != dend) {
902 while (fit != fend) {
939 for (;
i <
n.length(); ++
i) {
965 return QFileSystemEntry::removeUncOrLongPathPrefix(pathName).replace(u
'\\', u
'/');
995 newPath =
d->dirEntry.filePath();
996 if (!newPath.endsWith(u
'/'))
1001 ||
d->dirEntry.filePath() == u
'.') {
1014 if (newPath.startsWith(
".."_L1)) {
1021 dir->setPath(newPath);
1053 return d->nameFilters;
1078#ifndef QT_BOOTSTRAPPED
1081struct DirSearchPaths {
1083 QHash<QString, QStringList>
paths;
1111 if (prefix.size() < 2) {
1112 qWarning(
"QDir::setSearchPaths: Prefix must be longer than 1 character");
1117 if (!
ch.isLetterOrNumber()) {
1118 qWarning(
"QDir::setSearchPaths: Prefix can only contain letters or numbers");
1123 DirSearchPaths &conf = *dirSearchPaths;
1125 if (searchPaths.isEmpty()) {
1126 conf.paths.remove(prefix);
1128 conf.paths.insert(prefix, searchPaths);
1144 DirSearchPaths &conf = *dirSearchPaths;
1146 conf.paths[prefix] +=
path;
1158 if (!dirSearchPaths.exists())
1161 const DirSearchPaths &conf = *dirSearchPaths;
1163 return conf.paths.value(prefix);
1297#ifndef QT_BOOTSTRAPPED
1326 d->initFileLists(*
this);
1327 return d->fileCache.files.size();
1342 d->initFileLists(*
this);
1343 return d->fileCache.files[
pos];
1411 SortFlags sort)
const
1424 if (needsSorting ||
d->fileCache.fileListsInitialized) {
1425 d->initFileLists(*
this);
1426 return d->fileCache.files;
1434 for (
const auto &dirEntry : dirList)
1436 d->sortFileList(sort, l, &
ret,
nullptr);
1438 for (
const auto &dirEntry : dirList)
1439 ret.emplace_back(dirEntry.fileName());
1461 SortFlags sort)
const
1471 d->initFileLists(*
this);
1472 return d->fileCache.fileInfos;
1479 d->sortFileList(sort, l,
nullptr, &
ret);
1509 qWarning(
"QDir::mkdir: Empty or null file name");
1516 return d->fileEngine->mkdir(fn,
false, permissions);
1531 qWarning(
"QDir::mkdir: Empty or null file name");
1538 return d->fileEngine->mkdir(fn,
false);
1555 qWarning(
"QDir::rmdir: Empty or null file name");
1563 return d->fileEngine->rmdir(fn,
false);
1583 qWarning(
"QDir::mkpath: Empty or null file name");
1590 return d->fileEngine->mkdir(fn,
true);
1609 qWarning(
"QDir::rmpath: Empty or null file name");
1616 return d->fileEngine->rmdir(fn,
true);
1619#ifndef QT_BOOTSTRAPPED
1645 bool success =
true;
1649 for (
const auto &dirEntry :
QDirListing(dirPath, dirFilters)) {
1652 if (dirEntry.isDir() && !dirEntry.isSymLink()) {
1687 if (!
d->fileEngine) {
1696 const QAbstractFileEngine::FileFlags
info =
1791 std::unique_ptr<QDirPrivate>
dir;
1792 if (!!
d->fileEngine) {
1827 if (!
d->fileEngine || !
other->fileEngine) {
1828 if (
d->fileEngine.get() !=
other->fileEngine.get())
1833 if (
d->fileEngine->caseSensitive() !=
other->fileEngine->caseSensitive())
1838 if (
d->filters ==
other->filters
1839 &&
d->sort ==
other->sort
1840 &&
d->nameFilters ==
other->nameFilters) {
1843 if (
d->dirEntry.filePath() ==
other->dirEntry.filePath())
1855 QString thisFilePath =
d->resolveAbsoluteEntry();
1857 return thisFilePath.compare(otherFilePath, sensitive) == 0;
1901 qWarning(
"QDir::remove: Empty or null file name");
1925 if (oldName.isEmpty() || newName.isEmpty()) {
1926 qWarning(
"QDir::rename: Empty or null file name(s)");
1948 if (
name.isEmpty()) {
1949 qWarning(
"QDir::exists: Empty or null file name");
1955#ifndef QT_BOOTSTRAPPED
1973 return dirList.cbegin() == dirList.cend();
1989#ifdef QT_NO_FSFILEENGINE
2164#if QT_CONFIG(regularexpression)
2220 QVarLengthArray<char16_t> outVector(
len);
2222 char16_t *
out = outVector.data();
2223 const char16_t *
p =
reinterpret_cast<const char16_t *
>(
name.data());
2224 const char16_t *prefix =
p;
2233 if (
i > 0 &&
p[
i] ==
'/' && !isRemote) {
2239 return i > 1 &&
p[
i - 1] ==
'.' &&
p[
i - 2] ==
'/';
2241 auto isDotDot = [](
const char16_t *
p,
qsizetype i) {
2242 return i > 2 &&
p[
i - 1] ==
'.' &&
p[
i - 2] ==
'.' &&
p[
i - 3] ==
'/';
2248 if (isRemote && !up) {
2261 if (
p[
i] ==
'.' && (
i == 0 ||
p[
i-1] ==
'/')) {
2267 if (
i >= 1 &&
p[
i] ==
'.' &&
p[
i-1] ==
'.' && (
i < 2 ||
p[
i - 2] ==
'/')) {
2269 i -=
i >= 2 ? 3 : 2;
2273 while (
i > 0 && up &&
p[
i] ==
'/') {
2282 if (!up && used !=
len &&
out[used] !=
'/')
2289 if (isRemote && !up) {
2290 while (
i > 0 &&
p[
i] ==
'/' && !isDotDot(
p,
i)) {
2325 *
ok = prefixLength == 0 || up == 0;
2328 while (up && !isRemote) {
2329 if (used !=
len &&
out[used] !=
'/')
2336 bool isEmpty = used ==
len;
2339 if (!isEmpty &&
out[used] ==
'/') {
2345 out[--used] = prefix[
i];
2351 }
else if (
out[used] ==
'/') {
2367 if (
path.isEmpty()) {
2376 if (
ret.size() > 1 &&
ret.endsWith(u
'/')) {
2377#if defined (Q_OS_WIN)
2378 if (!(
ret.length() == 3 &&
ret.at(1) == u
':'))
2446#ifndef QT_NO_DEBUG_STREAM
2450 debug.resetFormat();
2453 flags <<
"NoFilter"_L1;
2471 debug.noquote() <<
"QDir::Filters(" <<
flags.join(u
'|') <<
')';
2478 debug.resetFormat();
2480 debug <<
"QDir::SortFlags(NoSort)";
2494 debug.noquote() <<
"QDir::SortFlags(" <<
type <<
'|' <<
flags.join(u
'|') <<
')';
2502 debug.resetFormat();
2503 debug <<
"QDir(" <<
dir.path() <<
", nameFilters = {"
2504 <<
dir.nameFilters().join(u
',')
void setCaseSensitivity(Qt::CaseSensitivity cs)
Sets the case-sensitivity of the collator to cs.
int compare(const QString &s1, const QString &s2) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore\reentrant
qint64 msecsTo(const QDateTime &) const
Returns the number of milliseconds from this datetime to the other datetime.
The QDirListing class provides an STL-style iterator for directory entries.
static QChar getFilterSepChar(const QString &nameFilter)
std::unique_ptr< QAbstractFileEngine > fileEngine
void setPath(const QString &path)
QFileSystemEntry dirEntry
void clearCache(MetaDataClearing mode)
void initFileLists(const QDir &dir) const
static void sortFileList(QDir::SortFlags, const QFileInfoList &, QStringList *, QFileInfoList *)
QString resolveAbsoluteEntry() const
QDirPrivate(const QString &path, const QStringList &nameFilters_=QStringList(), QDir::SortFlags sort_=QDir::SortFlags(QDir::Name|QDir::IgnoreCase), QDir::Filters filters_=QDir::AllEntries)
static QStringList splitFilters(const QString &nameFilter, QChar sep={})
bool operator()(const QDirSortItem &, const QDirSortItem &) const
QDirSortItemComparator(QDir::SortFlags flags, QCollator *coll=nullptr)
int compareStrings(const QString &a, const QString &b, Qt::CaseSensitivity cs) const
bool mkdir(const QString &dirName) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool remove(const QString &fileName)
Removes the file, fileName.
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString operator[](qsizetype) const
Returns the file name at position pos in the list of file names.
~QDir()
Destroys the QDir object frees up its resources.
bool cdUp()
Changes directory by moving one directory up from the QDir's current directory.
bool isRelative() const
Returns true if the directory path is relative; otherwise returns false.
QString dirName() const
Returns the name of the directory; this is not the same as the path, e.g.
qsizetype count(QT6_DECL_NEW_OVERLOAD) const
Returns the total number of directories and files in the directory.
QDir & operator=(const QDir &)
Move-assigns other to this QDir instance.
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
SortFlags sorting() const
Returns the value set by setSorting()
void refresh() const
Refreshes the directory information.
static QStringList nameFiltersFromString(const QString &nameFilter)
bool rmpath(const QString &dirPath) const
Removes the directory path dirPath.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
static QString fromNativeSeparators(const QString &pathName)
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
QString path() const
Returns the path.
static QStringList searchPaths(const QString &prefix)
bool cd(const QString &dirName)
Changes the QDir's directory to dirName.
QString canonicalPath() const
Returns the canonical path, i.e.
bool rename(const QString &oldName, const QString &newName)
Renames a file or directory from oldName to newName, and returns true if successful; otherwise return...
QSharedDataPointer< QDirPrivate > d_ptr
void setSorting(SortFlags sort)
Sets the sort order used by entryList() and entryInfoList().
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification),...
static void addSearchPath(const QString &prefix, const QString &path)
QFileInfoList entryInfoList(Filters filters=NoFilter, SortFlags sort=NoSort) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
static QFileInfoList drives()
Returns a list of the root directories on this system.
static QString tempPath()
Returns the absolute canonical path of the system's temporary directory.
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
bool makeAbsolute()
Converts the directory path to an absolute path.
void setFilter(Filters filter)
Sets the filter used by entryList() and entryInfoList() to filters.
static QString cleanPath(const QString &path)
Returns path with directory separators normalized (that is, platform-native separators converted to "...
void setPath(const QString &path)
Sets the path of the directory to path.
void setNameFilters(const QStringList &nameFilters)
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nam...
QString relativeFilePath(const QString &fileName) const
Returns the path to fileName relative to the directory.
static QString toNativeSeparators(const QString &pathName)
QString absoluteFilePath(const QString &fileName) const
Returns the absolute path name of a file in the directory.
bool isReadable() const
Returns true if the directory is readable and we can open files by name; otherwise returns false.
static QString homePath()
Returns the absolute path of the user's home directory.
bool isEmpty(Filters filters=Filters(AllEntries|NoDotAndDotDot)) const
Returns whether the directory is empty.
bool isRoot() const
Returns true if the directory is the root directory; otherwise returns false.
static QString currentPath()
Returns the absolute path of the application's current directory.
static QString rootPath()
Returns the absolute path of the root directory.
Filters filter() const
Returns the value set by setFilter()
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
QStringList nameFilters() const
Returns the string list set by setNameFilters()
static QFileInfoList drives()
For Windows, returns the list of drives in the file system as a list of QFileInfo objects.
QString suffix() const
Returns the suffix (extension) of the file.
QString absoluteFilePath() const
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
bool isRelative() const
Returns true if the file system entry's path is relative, otherwise returns false (that is,...
bool exists() const
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false.
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static bool setCurrentPath(const QFileSystemEntry &entry)
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
static QString rootPath()
static bool createDirectory(const QFileSystemEntry &entry, bool createParents, std::optional< QFile::Permissions > permissions=std::nullopt)
static std::unique_ptr< QAbstractFileEngine > createLegacyEngine(QFileSystemEntry &entry, QFileSystemMetaData &data)
static QString homePath()
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static QString tempPath()
static bool isCaseSensitive()
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
static QFileSystemEntry currentPath()
Q_AUTOTEST_EXPORT bool isEmpty() const
Q_AUTOTEST_EXPORT bool isClean() const
Q_AUTOTEST_EXPORT bool isRelative() const
Q_AUTOTEST_EXPORT bool isRoot() const
Q_AUTOTEST_EXPORT QString filePath() const
Q_AUTOTEST_EXPORT bool isAbsolute() const
bool setPermissions(Permissions permissionSpec) override
Sets the permissions for the file to the permissions specified.
bool remove()
Removes the file specified by fileName().
Permissions permissions() const override
\reimp
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const noexcept
bool isEmpty() const noexcept
reference emplace_back(Args &&... args)
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
const_iterator ConstIterator
static QRegularExpression fromWildcard(QStringView pattern, Qt::CaseSensitivity cs=Qt::CaseInsensitive, WildcardConversionOptions options=DefaultWildcardConversion)
const T * constData() const noexcept
Returns a const pointer to the shared data object.
T * data()
Returns a pointer to the shared data object.
constexpr void chop(qsizetype n) noexcept
Truncates this string view by length characters.
constexpr QStringView left(qsizetype n) const noexcept
QString toString() const
Returns a deep copy of this string view's data as a QString.
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void chop(qsizetype n)
Removes n characters from the end of the string.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
auto tokenize(Needle &&needle, Flags...flags) const &noexcept(noexcept(qTokenize(std::declval< const QString & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...))
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
QList< QString > QStringList
Constructs a string list that contains the given string, str.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static qsizetype rootLength(QStringView name, bool allowUncPaths)
QDebug operator<<(QDebug debug, QDir::Filters filters)
bool comparesEqual(const QDir &lhs, const QDir &rhs)
static QString qt_cleanPath(const QString &path, bool *ok=nullptr)
static bool treatAsAbsolute(const QString &path)
QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormalizations flags, bool *ok)
QList< QFileInfo > QFileInfoList
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLuint * paths
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei const GLchar *const * path
static constexpr QChar sep
#define qUtf8Printable(string)
constexpr auto qTokenize(Haystack &&h, Needle &&n, Flags...flags) noexcept(QtPrivate::Tok::is_nothrow_constructible_from< Haystack, Needle >::value) -> decltype(QtPrivate::Tok::TokenizerResult< Haystack, Needle >{std::forward< Haystack >(h), std::forward< Needle >(n), flags...})
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
#define QT6_IMPL_NEW_OVERLOAD
static int toInt(const QChar &qc, int R)
QTextStream out(stdout)
[7]
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
std::atomic< bool > fileListsInitialized
QFileSystemEntry absoluteDirEntry
QFileSystemMetaData metaData
QDirSortItem(const QFileInfo &fi, QDir::SortFlags sort)