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);
268 r = firstModified.
msecsTo(secondModified);
320#ifndef QT_BOOTSTRAPPED
333 auto &fileInfo = si[
i].item;
337 const bool cached = !si[
i].filename_cache.
isNull();
338 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) {
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;
857 fileDrive = dirDrive;
858 fileDriveMissing =
true;
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();
1001 ||
d->dirEntry.filePath() == u
'.') {
1021 dir->setPath(newPath);
1053 return d->nameFilters;
1078#ifndef QT_BOOTSTRAPPED
1081struct DirSearchPaths {
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);
1325 d->initFileLists(*
this);
1326 return d->fileCache.files.size();
1341 d->initFileLists(*
this);
1342 return d->fileCache.files[
pos];
1410 SortFlags sort)
const
1423 if (needsSorting ||
d->fileCache.fileListsInitialized) {
1424 d->initFileLists(*
this);
1425 return d->fileCache.files;
1433 while (
it.hasNext())
1435 d->sortFileList(sort, l, &
ret,
nullptr);
1437 while (
it.hasNext()) {
1439 ret.append(
it.fileName());
1462 SortFlags sort)
const
1472 d->initFileLists(*
this);
1473 return d->fileCache.fileInfos;
1478 while (
it.hasNext())
1481 d->sortFileList(sort, l,
nullptr, &
ret);
1510 qWarning(
"QDir::mkdir: Empty or null file name");
1517 return d->fileEngine->mkdir(fn,
false, permissions);
1532 qWarning(
"QDir::mkdir: Empty or null file name");
1539 return d->fileEngine->mkdir(fn,
false);
1556 qWarning(
"QDir::rmdir: Empty or null file name");
1564 return d->fileEngine->rmdir(fn,
false);
1584 qWarning(
"QDir::mkpath: Empty or null file name");
1591 return d->fileEngine->mkdir(fn,
true);
1610 qWarning(
"QDir::rmpath: Empty or null file name");
1617 return d->fileEngine->rmdir(fn,
true);
1645 bool success =
true;
1687 if (!
d->fileEngine) {
1696 const QAbstractFileEngine::FileFlags
info =
1791 std::unique_ptr<QDirPrivate>
dir;
1792 if (!!
d->fileEngine) {
1825 if (!
d->fileEngine || !
other->fileEngine) {
1826 if (
d->fileEngine.get() !=
other->fileEngine.get())
1831 if (
d->fileEngine->caseSensitive() !=
other->fileEngine->caseSensitive())
1836 if (
d->filters ==
other->filters
1837 &&
d->sort ==
other->sort
1838 &&
d->nameFilters ==
other->nameFilters) {
1841 if (
d->dirEntry.filePath() ==
other->dirEntry.filePath())
1853 QString thisFilePath =
d->resolveAbsoluteEntry();
1855 return thisFilePath.
compare(otherFilePath, sensitive) == 0;
1900 qWarning(
"QDir::remove: Empty or null file name");
1925 qWarning(
"QDir::rename: Empty or null file name(s)");
1947 if (
name.isEmpty()) {
1948 qWarning(
"QDir::exists: Empty or null file name");
1971 return !
it.hasNext();
1986#ifdef QT_NO_FSFILEENGINE
2161#if QT_CONFIG(regularexpression)
2219 char16_t *
out = outVector.
data();
2220 const char16_t *
p =
reinterpret_cast<const char16_t *
>(
name.data());
2221 const char16_t *prefix =
p;
2230 if (
i > 0 &&
p[
i] ==
'/' && !isRemote) {
2236 return i > 1 &&
p[
i - 1] ==
'.' &&
p[
i - 2] ==
'/';
2238 auto isDotDot = [](
const char16_t *
p,
qsizetype i) {
2239 return i > 2 &&
p[
i - 1] ==
'.' &&
p[
i - 2] ==
'.' &&
p[
i - 3] ==
'/';
2245 if (isRemote && !up) {
2258 if (
p[
i] ==
'.' && (
i == 0 ||
p[
i-1] ==
'/')) {
2264 if (
i >= 1 &&
p[
i] ==
'.' &&
p[
i-1] ==
'.' && (
i < 2 ||
p[
i - 2] ==
'/')) {
2266 i -=
i >= 2 ? 3 : 2;
2270 while (
i > 0 && up &&
p[
i] ==
'/') {
2279 if (!up && used !=
len &&
out[used] !=
'/')
2286 if (isRemote && !up) {
2287 while (
i > 0 &&
p[
i] ==
'/' && !isDotDot(
p,
i)) {
2322 *
ok = prefixLength == 0 || up == 0;
2325 while (up && !isRemote) {
2326 if (used !=
len &&
out[used] !=
'/')
2333 bool isEmpty = used ==
len;
2336 if (!isEmpty &&
out[used] ==
'/') {
2342 out[--used] = prefix[
i];
2348 }
else if (
out[used] ==
'/') {
2364 if (
path.isEmpty()) {
2373 if (
ret.size() > 1 &&
ret.endsWith(u
'/')) {
2374#if defined (Q_OS_WIN)
2375 if (!(
ret.length() == 3 &&
ret.at(1) == u
':'))
2443#ifndef QT_NO_DEBUG_STREAM
2447 debug.resetFormat();
2450 flags <<
"NoFilter"_L1;
2468 debug.noquote() <<
"QDir::Filters(" <<
flags.join(u
'|') <<
')';
2475 debug.resetFormat();
2477 debug <<
"QDir::SortFlags(NoSort)";
2491 debug.noquote() <<
"QDir::SortFlags(" <<
type <<
'|' <<
flags.join(u
'|') <<
')';
2499 debug.resetFormat();
2500 debug <<
"QDir(" <<
dir.path() <<
", nameFilters = {"
2501 <<
dir.nameFilters().join(u
',')
constexpr bool isNull() const noexcept
Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false.
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 QDirIterator class provides an iterator for directory entrylists.
bool hasNext() const
Returns true if there is at least one more entry in the directory; otherwise, false is returned.
QString filePath() const
Returns the full file path for the current directory entry.
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.
bool operator==(const QDir &dir) const
Returns true if directory dir and this directory have the same path and their sort and filter setting...
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.
\inmodule QtCore \reentrant
QDateTime lastModified() const
Returns the date and time when the file was last modified.
bool isSymLink() const
Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
QString suffix() const
Returns the suffix (extension) of the file.
QString fileName() const
Returns the name of the file, excluding the path.
QString absoluteFilePath() const
Returns an absolute path including the file name.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
qint64 size() const
Returns the file size in bytes.
bool isRelative() const
Returns true if the file path is relative, otherwise returns false (i.e.
bool exists() const
Returns true if the file exists; otherwise returns false.
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static QAbstractFileEngine * resolveEntryAndCreateLegacyEngine(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 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
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)
T * data() const noexcept
Returns the value of the pointer referenced by this object.
bool isNull() const noexcept
Returns true if this object refers to \nullptr.
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.
int compare(QStringView other, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromUtf16(const char16_t *, qsizetype size=-1)
const QChar * constData() const
Returns a pointer to the data stored in the QString.
bool isNull() const
Returns true if this string is null; otherwise returns false.
qsizetype size() const
Returns the number of characters in this string.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
QString toLower() const &
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
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...))
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
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)
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]
GLsizei const GLuint * paths
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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)
QFileInfo info(fileName)
[8]
QFileInfo fi("c:/temp/foo")
[newstuff]
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)