42 #include "qplatformdefs.h" 46 #ifndef QT_NO_DEBUG_STREAM 62 #ifdef QT_BUILD_CORE_LIB 64 # include "private/qcoreglobaldata_p.h" 73 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) 77 if (c < 'a' && c >
'z' && c < 'A' && c >
'Z')
81 return path.
mid(0, 2);
91 , nameFilters(nameFilters_)
98 , fileListsInitialized(false)
122 , filterSepChar(copy.filterSepChar)
123 , matchAllDirs(copy.matchAllDirs)
138 const QAbstractFileEngine::FileFlags
info =
151 int i = nameFilter.
indexOf(sep, 0);
163 for (
int i = 0; i < ret.
count(); ++i)
173 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) 304 for (
int i = 0; i < n; ++i)
309 for (
int i = 0; i < n; ++i)
310 si[i].item = l.
at(i);
314 for (
int i = 0; i < n; ++i)
315 infos->
append(si[i].item);
318 for (
int i = 0; i < n; ++i)
319 names->
append(si[i].item.fileName());
733 bool fileDriveMissing =
false;
735 fileDrive = dirDrive;
736 fileDriveMissing =
true;
743 #elif defined(Q_OS_SYMBIAN) 746 if (fileDrive != dirDrive)
751 if (!fileDriveMissing)
759 while (i < dirElts.
size() && i < fileElts.
size() &&
760 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) 763 dirElts.
at(i) == fileElts.
at(i))
767 for (
int j = 0; j < dirElts.
size() - i; ++j)
770 for (
int j = i; j < fileElts.
size(); ++j) {
771 result += fileElts.
at(j);
772 if (j < fileElts.
size() - 1)
779 #ifndef QT_NO_DEPRECATED 814 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) 822 for (; i < n.
length(); ++i) {
850 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) 858 for (; i < n.
length(); ++i) {
991 #ifdef QT_BUILD_CORE_LIB 998 #ifdef QT_BUILD_CORE_LIB 1024 if (prefix.
length() < 2) {
1025 qWarning(
"QDir::setSearchPaths: Prefix must be longer than 1 character");
1029 for (
int i = 0; i < prefix.
count(); ++i) {
1031 qWarning(
"QDir::setSearchPaths: Prefix can only contain letters or numbers");
1041 paths.
insert(prefix, searchPaths);
1080 #endif // QT_BUILD_CORE_LIB 1265 return d->
files[pos];
1339 SortFlags
sort)
const 1346 if (d->matchAllDirs)
1359 while (
it.hasNext()) {
1385 SortFlags
sort)
const 1392 if (d->matchAllDirs)
1405 while (
it.hasNext()) {
1429 qWarning(
"QDir::mkdir: Empty or null file name(s)");
1453 qWarning(
"QDir::rmdir: Empty or null file name(s)");
1482 qWarning(
"QDir::mkpath: Empty or null file name(s)");
1508 qWarning(
"QDir::rmpath: Empty or null file name(s)");
1538 const QAbstractFileEngine::FileFlags
info =
1754 qWarning(
"QDir::remove: Empty or null file name");
1774 qWarning(
"QDir::rename: Empty or null file name(s)");
1797 qWarning(
"QDir::exists: Empty or null file name");
1814 #ifdef QT_NO_FSFILEENGINE 1833 #if defined (Q_FS_FAT) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) 1835 #elif defined(Q_OS_UNIX) 1837 #elif defined (Q_OS_MAC) 2034 #ifndef QT_NO_REGEXP 2069 #endif // QT_NO_REGEXP 2091 int used = 0, levels = 0;
2092 const int len = name.
length();
2097 for (
int i = 0, last = -1, iwrite = 0; i < len; ++i) {
2100 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths 2111 if (i == len - dotcount - 1) {
2112 if (dotcount == 1) {
2114 }
else if (levels) {
2116 for (
int i2 = iwrite-1; i2 >= 0; i2--) {
2123 used -= iwrite - last - 1;
2127 if (dotcount == 2 && levels) {
2128 if (last == -1 || iwrite - last == 1) {
2129 for (
int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) {
2141 used -= iwrite - last;
2145 }
else if (dotcount == 2 && i > 0 && p[i - 1] !=
QLatin1Char(
'.')) {
2147 used -= iwrite -
qMax(0, last);
2148 iwrite =
qMax(0, last);
2151 }
else if (dotcount == 1) {
2159 }
else if (last != -1 && iwrite - last == 1) {
2160 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) 2161 eaten = (iwrite > 2);
2166 }
else if (last != -1 && i == len-1) {
2172 last = i - (i - iwrite);
2179 if (len >= dotcount && p[dotcount] ==
QLatin1Char(
'/')) {
2180 if (dotcount == 1) {
2188 out[iwrite++] = p[i];
2195 #if defined (Q_OS_WIN) || defined (Q_OS_SYMBIAN) 2309 bool QDir::matchAllDirs()
const 2312 return d->matchAllDirs;
2324 void QDir::setMatchAllDirs(
bool on)
2330 d->matchAllDirs = on;
2336 QString QDir::nameFilter()
const 2362 void QDir::setNameFilter(
const QString &nameFilter)
2473 #endif // QT3_SUPPORT 2475 #ifndef QT_NO_DEBUG_STREAM 2506 debug <<
"QDir::SortFlags(NoSort)";
2520 debug <<
"QDir::SortFlags(" <<
qPrintable(type)
2530 <<
", nameFilters = {" 2537 return debug.
space();
2539 #endif // QT_NO_DEBUG_STREAM bool isNull() const
Returns true if this object is holding a pointer that is null.
The QDir class provides access to directory structures and their contents.
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
The QDebug class provides an output stream for debugging information.
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const
This function should return the set of OR'd flags that are true for the file engine's file...
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
~QDir()
Destroys the QDir object frees up its resources.
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
bool operator()(const QDirSortItem &, const QDirSortItem &)
static mach_timebase_info_data_t info
static bool match(const QStringList &filters, const QString &fileName)
Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; othe...
#define QT_END_NAMESPACE
This macro expands to.
static QString rootPath()
QString operator[](int) const
Returns the file name at position pos in the list of file names.
QList< QFileInfo > QFileInfoList
bool hasNext() const
Returns true if there is at least one more entry in the directory; otherwise, false is returned...
QString absoluteFilePath(const QString &fileName) const
Returns the absolute path name of a file in the directory.
const QChar at(int i) const
Returns the character at the given index position in the string.
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
The QRegExp class provides pattern matching using regular expressions.
virtual QString fileName(FileName file=DefaultName) const
Return the file engine's current file name in the format specified by file.
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
T * data() const
Returns the value of the pointer referenced by this object.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
#define it(className, varName)
static QStringList splitFilters(const QString &nameFilter, QChar sep=0)
void setPath(const QString &path)
Sets the path of the directory to path.
virtual bool isRelativePath() const
Return true if the file referred to by this file engine has a relative path; otherwise return false...
void setPath(const QString &path)
T * data()
Returns a pointer to the shared data object.
static QChar getFilterSepChar(const QString &nameFilter)
SortFlags sorting() const
Returns the value set by setSorting()
bool isRelative() const
Returns true if the directory path is relative; otherwise returns false.
QString & replace(int i, int len, QChar after)
void chop(int n)
Removes n characters from the end of the string.
int length() const
Returns the number of characters in this string.
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const
Requests that the directory dirName is deleted from the file system.
T * take()
Returns the value of the pointer referenced by this object.
static QString driveSpec(const QString &path)
QFileSystemEntry dirEntry
QString fileName() const
Returns the name of the file, excluding the path.
QDirSortItemComparator(int flags)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
bool mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString absoluteFilePath() const
Returns an absolute path including the file name.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
The QDirIterator class provides an iterator for directory entrylists.
The QString class provides a Unicode character string.
static QString currentPath()
Returns the absolute path of the application's current directory.
uint count() const
Returns the total number of directories and files in the directory.
QFileInfo fileInfo() const
Returns a QFileInfo for the current directory entry.
static bool isCaseSensitive()
QDebug operator<<(QDebug debug, QDir::Filters filters)
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
The QChar class provides a 16-bit Unicode character.
QChar * data()
Returns a pointer to the data stored in the QString.
bool fileListsInitialized
QScopedPointer< QAbstractFileEngine > fileEngine
bool exists() const
Returns true if the directory exists; otherwise returns false.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void setNameFilters(const QStringList &nameFilters)
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nam...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static QFileSystemEntry currentPath()
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
void refresh() const
Refreshes the directory information.
bool cdUp()
Changes directory by moving one directory up from the QDir's current directory.
void append(const T &t)
Inserts value at the end of the list.
bool rename(const QString &oldName, const QString &newName)
Renames a file or directory from oldName to newName, and returns true if successful; otherwise return...
bool isReadable() const
Returns true if the directory is readable and we can open files by name; otherwise returns false...
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
static void addSearchPath(const QString &prefix, const QString &path)
static QString tempPath()
void truncate(int pos)
Truncates the string at the given position index.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
static QT_DEPRECATED QString convertSeparators(const QString &pathName)
Use QDir::toNativeSeparators() instead.
virtual bool caseSensitive() const
Should return true if the underlying file system is case-sensitive; otherwise return false...
static void sort(T *array, int count, LessThan lessThan)
int size() const
Returns the number of characters in this string.
const QChar * unicode() const
Returns a '\0'-terminated Unicode representation of the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
QStringList nameFilters() const
Returns the string list set by setNameFilters()
bool rmpath(const QString &dirPath) const
Removes the directory path dirPath.
static void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *)
const T value(const Key &key) const
Returns the value associated with the key key.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
static void addSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
Q_CORE_EXPORT void qWarning(const char *,...)
const T * constData() const
Returns a const pointer to the shared data object.
static QFileInfoList drives()
For Windows, returns the list of drives in the file system as a list of QFileInfo objects...
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
static void setSearchPaths(const QString &prefix, const QStringList &searchPaths)
QFileInfoList entryInfoList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
QDebug & maybeSpace()
Writes a space character to the debug stream, depending on the last character sent to the stream...
static QFileInfoList drives()
Returns a list of the root directories on this system.
void clear()
Removes all items from the list.
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects...
bool cd(const QString &dirName)
Changes the QDir's directory to dirName.
void qSort(RandomAccessIterator start, RandomAccessIterator end)
int localeAwareCompare(const QString &s) const
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QDir & operator=(const QDir &)
Makes a copy of the dir object and assigns it to this QDir object.
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
char toAscii() const
Returns the character value of the QChar obtained using the current codec used to read C strings...
static QString tempPath()
Returns the absolute path of the system's temporary directory.
bool isNull() const
Returns true if this string is null; otherwise returns false.
QString join(const QString &sep) const
Joins all the string list's strings into a single string with each element separated by the given sep...
int remove(const Key &key)
Removes all the items that have the key key from the map.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
void setSorting(SortFlags sort)
Sets the sort order used by entryList() and entryInfoList().
static bool setCurrentPath(const QFileSystemEntry &entry)
static const char *const filters[3]
QString next()
Advances the iterator to the next entry, and returns the file path of this new entry.
int compare(const QString &s) const
qint64 size() const
Returns the file size in bytes.
The QFile class provides an interface for reading from and writing to files.
QString trimmed(QString source)
The QSharedData class is a base class for shared data objects.
static QCoreGlobalData * instance()
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
QString relativeFilePath(const QString &fileName) const
Returns the path to fileName relative to the directory.
static QStringList nameFiltersFromString(const QString &nameFilter)
Returns a list of name filters from the given nameFilter.
QString suffix() const
Returns the suffix of the file.
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
Filters filter() const
Returns the value set by setFilter()
int size() const
Returns the number of items in the list.
bool isRelative() const
Returns true if the file path name is relative, otherwise returns false if the path is absolute (e...
static QReadWriteLock lock
QString canonicalPath() const
Returns the canonical path, i.e.
static QString homePath()
static QStringList searchPaths(const QString &prefix)
static QString rootPath()
Returns the absolute path of the root directory.
bool remove()
Removes the file specified by fileName().
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
QFileSystemMetaData metaData
bool remove(const QString &fileName)
Removes the file, fileName.
QSharedDataPointer< QDirPrivate > d_ptr
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
static QAbstractFileEngine * resolveEntryAndCreateLegacyEngine(QFileSystemEntry &entry, QFileSystemMetaData &data)
Resolves the entry (see QDir::searchPaths) and returns an engine for it, but never a QFSFileEngine...
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const
Requests that the directory dirName be created.
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using '/' as file separator.
QString path() const
Returns the path.
void resolveAbsoluteEntry() const
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
QFileSystemEntry absoluteDirEntry
bool operator==(const QDir &dir) const
Returns true if directory dir and this directory have the same path and their sort and filter setting...
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
The QFileInfo class provides system-independent file information.
QString dirName() const
Returns the name of the directory; this is not the same as the path, e.g.
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the '/' separators converted to separators that are appropriate for the underly...
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
bool isRoot() const
Returns true if the directory is the root directory; otherwise returns false.
#define qPrintable(string)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of the names of all the files and directories in the directory, ordered according to t...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void initFileLists(const QDir &dir) const
static void addResourceSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
void setFilter(Filters filter)
Sets the filter used by entryList() and entryInfoList() to filters.
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
QMap< QString, QStringList > dirSearchPaths
bool makeAbsolute()
Converts the directory path to an absolute path.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
QDirPrivate(const QString &path, const QStringList &nameFilters_=QStringList(), QDir::SortFlags sort_=QDir::SortFlags(QDir::Name|QDir::IgnoreCase), QDir::Filters filters_=QDir::AllEntries)
static QString homePath()
Returns the absolute path of the user's home directory.
QDateTime lastModified() const
Returns the date and time when the file was last modified.