Qt 4.8
qdir.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qplatformdefs.h"
43 #include "qdir.h"
44 #include "qdir_p.h"
45 #include "qabstractfileengine.h"
46 #ifndef QT_NO_DEBUG_STREAM
47 #include "qdebug.h"
48 #endif
49 #include "qdiriterator.h"
50 #include "qfsfileengine.h"
51 #include "qdatetime.h"
52 #include "qstring.h"
53 #include "qregexp.h"
54 #include "qvector.h"
55 #include "qalgorithms.h"
56 #include "qvarlengtharray.h"
57 #include "qfilesystementry_p.h"
58 #include "qfilesystemmetadata_p.h"
59 #include "qfilesystemengine_p.h"
60 #include <qstringbuilder.h>
61 
62 #ifdef QT_BUILD_CORE_LIB
63 # include "qresource.h"
64 # include "private/qcoreglobaldata_p.h"
65 #endif
66 
67 #include <stdlib.h>
68 
70 
71 static QString driveSpec(const QString &path)
72 {
73 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
74  if (path.size() < 2)
75  return QString();
76  char c = path.at(0).toAscii();
77  if (c < 'a' && c > 'z' && c < 'A' && c > 'Z')
78  return QString();
79  if (path.at(1).toAscii() != ':')
80  return QString();
81  return path.mid(0, 2);
82 #else
83  Q_UNUSED(path);
84  return QString();
85 #endif
86 }
87 
88 //************* QDirPrivate
89 QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, QDir::SortFlags sort_, QDir::Filters filters_)
90  : QSharedData()
91  , nameFilters(nameFilters_)
92  , sort(sort_)
93  , filters(filters_)
94 #ifdef QT3_SUPPORT
95  , filterSepChar(0)
96  , matchAllDirs(false)
97 #endif
98  , fileListsInitialized(false)
99 {
100  setPath(path.isEmpty() ? QString::fromLatin1(".") : path);
101 
102  bool empty = nameFilters.isEmpty();
103  if (!empty) {
104  empty = true;
105  for (int i = 0; i < nameFilters.size(); ++i) {
106  if (!nameFilters.at(i).isEmpty()) {
107  empty = false;
108  break;
109  }
110  }
111  }
112  if (empty)
114 }
115 
117  : QSharedData(copy)
118  , nameFilters(copy.nameFilters)
119  , sort(copy.sort)
120  , filters(copy.filters)
121 #ifdef QT3_SUPPORT
122  , filterSepChar(copy.filterSepChar)
123  , matchAllDirs(copy.matchAllDirs)
124 #endif
125  , fileListsInitialized(false)
126  , dirEntry(copy.dirEntry)
127  , metaData(copy.metaData)
128 {
129 }
130 
132 {
133  if (fileEngine.isNull()) {
136  return metaData.exists() && metaData.isDirectory();
137  }
138  const QAbstractFileEngine::FileFlags info =
143  return false;
144  return info & QAbstractFileEngine::ExistsFlag;
145 }
146 
147 // static
148 inline QChar QDirPrivate::getFilterSepChar(const QString &nameFilter)
149 {
150  QChar sep(QLatin1Char(';'));
151  int i = nameFilter.indexOf(sep, 0);
152  if (i == -1 && nameFilter.indexOf(QLatin1Char(' '), 0) != -1)
153  sep = QChar(QLatin1Char(' '));
154  return sep;
155 }
156 
157 // static
158 inline QStringList QDirPrivate::splitFilters(const QString &nameFilter, QChar sep)
159 {
160  if (sep == 0)
161  sep = getFilterSepChar(nameFilter);
162  QStringList ret = nameFilter.split(sep);
163  for (int i = 0; i < ret.count(); ++i)
164  ret[i] = ret[i].trimmed();
165  return ret;
166 }
167 
168 inline void QDirPrivate::setPath(const QString &path)
169 {
171  if (p.endsWith(QLatin1Char('/'))
172  && p.length() > 1
173 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
174  && (!(p.length() == 3 && p.at(1).unicode() == ':' && p.at(0).isLetter()))
175 #endif
176  ) {
177  p.truncate(p.length() - 1);
178  }
179 
181  metaData.clear();
182  initFileEngine();
183  clearFileLists();
185 }
186 
188 {
189  fileListsInitialized = false;
190  files.clear();
191  fileInfos.clear();
192 }
193 
195 {
197  return;
198 
199  QString absoluteName;
200  if (fileEngine.isNull()) {
201  if (!dirEntry.isRelative() && dirEntry.isClean()) {
203  return;
204  }
205 
207  } else {
209  }
210 
212 }
213 
214 /* For sorting */
216 {
220 };
221 
222 
224 {
226 public:
227  QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {}
228  bool operator()(const QDirSortItem &, const QDirSortItem &);
229 };
230 
232 {
233  const QDirSortItem* f1 = &n1;
234  const QDirSortItem* f2 = &n2;
235 
236  if ((qt_cmp_si_sort_flags & QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir()))
237  return f1->item.isDir();
238  if ((qt_cmp_si_sort_flags & QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir()))
239  return !f1->item.isDir();
240 
241  int r = 0;
242  int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask)
243  | (qt_cmp_si_sort_flags & QDir::Type);
244 
245  switch (sortBy) {
246  case QDir::Time:
247  r = f1->item.lastModified().secsTo(f2->item.lastModified());
248  break;
249  case QDir::Size:
250  r = int(qBound<qint64>(-1, f2->item.size() - f1->item.size(), 1));
251  break;
252  case QDir::Type:
253  {
254  bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase;
255 
256  if (f1->suffix_cache.isNull())
257  f1->suffix_cache = ic ? f1->item.suffix().toLower()
258  : f1->item.suffix();
259  if (f2->suffix_cache.isNull())
260  f2->suffix_cache = ic ? f2->item.suffix().toLower()
261  : f2->item.suffix();
262 
263  r = qt_cmp_si_sort_flags & QDir::LocaleAware
265  : f1->suffix_cache.compare(f2->suffix_cache);
266  }
267  break;
268  default:
269  ;
270  }
271 
272  if (r == 0 && sortBy != QDir::Unsorted) {
273  // Still not sorted - sort by name
274  bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase;
275 
276  if (f1->filename_cache.isNull())
277  f1->filename_cache = ic ? f1->item.fileName().toLower()
278  : f1->item.fileName();
279  if (f2->filename_cache.isNull())
280  f2->filename_cache = ic ? f2->item.fileName().toLower()
281  : f2->item.fileName();
282 
283  r = qt_cmp_si_sort_flags & QDir::LocaleAware
286  }
287  if (r == 0) // Enforce an order - the order the items appear in the array
288  r = (&n1) - (&n2);
289  if (qt_cmp_si_sort_flags & QDir::Reversed)
290  return r > 0;
291  return r < 0;
292 }
293 
294 inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l,
295  QStringList *names, QFileInfoList *infos)
296 {
297  // names and infos are always empty lists or 0 here
298  int n = l.size();
299  if (n > 0) {
300  if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) {
301  if (infos)
302  *infos = l;
303  if (names) {
304  for (int i = 0; i < n; ++i)
305  names->append(l.at(i).fileName());
306  }
307  } else {
309  for (int i = 0; i < n; ++i)
310  si[i].item = l.at(i);
311  qSort(si.data(), si.data() + n, QDirSortItemComparator(sort));
312  // put them back in the list(s)
313  if (infos) {
314  for (int i = 0; i < n; ++i)
315  infos->append(si[i].item);
316  }
317  if (names) {
318  for (int i = 0; i < n; ++i)
319  names->append(si[i].item.fileName());
320  }
321  }
322  }
323 }
324 inline void QDirPrivate::initFileLists(const QDir &dir) const
325 {
326  if (!fileListsInitialized) {
328  QDirIterator it(dir);
329  while (it.hasNext()) {
330  it.next();
331  l.append(it.fileInfo());
332  }
334  fileListsInitialized = true;
335  }
336 }
337 
339 {
341 }
342 
527 QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(path))
528 {
529 }
530 
549 QDir::QDir(const QString &path, const QString &nameFilter,
550  SortFlags sort, Filters filters)
551  : d_ptr(new QDirPrivate(path, QDir::nameFiltersFromString(nameFilter), sort, filters))
552 {
553 }
554 
561 QDir::QDir(const QDir &dir)
562  : d_ptr(dir.d_ptr)
563 {
564 }
565 
571 {
572 }
573 
591 {
592  d_ptr->setPath(path);
593 }
594 
606 {
607  const QDirPrivate* d = d_ptr.constData();
608  return d->dirEntry.filePath();
609 }
610 
620 {
621  const QDirPrivate* d = d_ptr.constData();
623  return d->absoluteDirEntry.filePath();
624 }
625 
643 {
644  const QDirPrivate* d = d_ptr.constData();
645  if (d->fileEngine.isNull()) {
647  return answer.filePath();
648  }
650 }
651 
664 {
665  const QDirPrivate* d = d_ptr.constData();
666  return d->dirEntry.fileName();
667 }
668 
679 {
680  const QDirPrivate* d = d_ptr.constData();
681  if (isAbsolutePath(fileName))
682  return QString(fileName);
683 
684  QString ret = d->dirEntry.filePath();
685  if (!fileName.isEmpty()) {
686  if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/'))
687  ret += QLatin1Char('/');
688  ret += fileName;
689  }
690  return ret;
691 }
692 
702 {
703  const QDirPrivate* d = d_ptr.constData();
704  if (isAbsolutePath(fileName))
705  return fileName;
706 
708  if (fileName.isEmpty())
709  return d->absoluteDirEntry.filePath();
710  if (!d->absoluteDirEntry.isRoot())
711  return d->absoluteDirEntry.filePath() % QLatin1Char('/') % fileName;
712  return d->absoluteDirEntry.filePath() % fileName;
713 }
714 
723 {
724  QString dir = cleanPath(absolutePath());
725  QString file = cleanPath(fileName);
726 
727  if (isRelativePath(file) || isRelativePath(dir))
728  return file;
729 
730  QString dirDrive = driveSpec(dir);
731  QString fileDrive = driveSpec(file);
732 
733  bool fileDriveMissing = false;
734  if (fileDrive.isEmpty()) {
735  fileDrive = dirDrive;
736  fileDriveMissing = true;
737  }
738 
739 #ifdef Q_OS_WIN
740  if (fileDrive.toLower() != dirDrive.toLower()
741  || (file.startsWith(QLatin1String("//"))
742  && !dir.startsWith(QLatin1String("//"))))
743 #elif defined(Q_OS_SYMBIAN)
744  if (fileDrive.toLower() != dirDrive.toLower())
745 #else
746  if (fileDrive != dirDrive)
747 #endif
748  return file;
749 
750  dir.remove(0, dirDrive.size());
751  if (!fileDriveMissing)
752  file.remove(0, fileDrive.size());
753 
754  QString result;
756  QStringList fileElts = file.split(QLatin1Char('/'), QString::SkipEmptyParts);
757 
758  int i = 0;
759  while (i < dirElts.size() && i < fileElts.size() &&
760 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
761  dirElts.at(i).toLower() == fileElts.at(i).toLower())
762 #else
763  dirElts.at(i) == fileElts.at(i))
764 #endif
765  ++i;
766 
767  for (int j = 0; j < dirElts.size() - i; ++j)
768  result += QLatin1String("../");
769 
770  for (int j = i; j < fileElts.size(); ++j) {
771  result += fileElts.at(j);
772  if (j < fileElts.size() - 1)
773  result += QLatin1Char('/');
774  }
775 
776  return result;
777 }
778 
779 #ifndef QT_NO_DEPRECATED
780 
789 {
790  return toNativeSeparators(pathName);
791 }
792 #endif
793 
813 {
814 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
815  int i = pathName.indexOf(QLatin1Char('/'));
816  if (i != -1) {
817  QString n(pathName);
818 
819  QChar * const data = n.data();
820  data[i++] = QLatin1Char('\\');
821 
822  for (; i < n.length(); ++i) {
823  if (data[i] == QLatin1Char('/'))
824  data[i] = QLatin1Char('\\');
825  }
826 
827  return n;
828  }
829 #endif
830  return pathName;
831 }
832 
849 {
850 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
851  int i = pathName.indexOf(QLatin1Char('\\'));
852  if (i != -1) {
853  QString n(pathName);
854 
855  QChar * const data = n.data();
856  data[i++] = QLatin1Char('/');
857 
858  for (; i < n.length(); ++i) {
859  if (data[i] == QLatin1Char('\\'))
860  data[i] = QLatin1Char('/');
861  }
862 
863  return n;
864  }
865 #endif
866  return pathName;
867 }
868 
881 {
882  // Don't detach just yet.
883  const QDirPrivate * const d = d_ptr.constData();
884 
885  if (dirName.isEmpty() || dirName == QLatin1String("."))
886  return true;
887  QString newPath;
888  if (isAbsolutePath(dirName)) {
889  newPath = cleanPath(dirName);
890  } else {
891  if (isRoot()) {
892  if (dirName == QLatin1String(".."))
893  return false;
894  newPath = d->dirEntry.filePath();
895  } else {
896  newPath = d->dirEntry.filePath() % QLatin1Char('/');
897  }
898 
899  newPath += dirName;
900  if (dirName.indexOf(QLatin1Char('/')) >= 0
901  || dirName == QLatin1String("..")
902  || d->dirEntry.filePath() == QLatin1String(".")) {
903  newPath = cleanPath(newPath);
904  /*
905  If newPath starts with .., we convert it to absolute to
906  avoid infinite looping on
907 
908  QDir dir(".");
909  while (dir.cdUp())
910  ;
911  */
912  if (newPath.startsWith(QLatin1String(".."))) {
913  newPath = QFileInfo(newPath).absoluteFilePath();
914  }
915  }
916  }
917 
919  dir->setPath(newPath);
920  if (!dir->exists())
921  return false;
922 
923  d_ptr = dir.take();
924  return true;
925 }
926 
938 {
939  return cd(QString::fromLatin1(".."));
940 }
941 
946 {
947  const QDirPrivate* d = d_ptr.constData();
948  return d->nameFilters;
949 }
950 
967 {
968  QDirPrivate* d = d_ptr.data();
969  d->initFileEngine();
970  d->clearFileLists();
971 
973 }
974 
990 {
991 #ifdef QT_BUILD_CORE_LIB
993 #else
994  Q_UNUSED(path)
995 #endif
996 }
997 
998 #ifdef QT_BUILD_CORE_LIB
999 
1022 void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths)
1023 {
1024  if (prefix.length() < 2) {
1025  qWarning("QDir::setSearchPaths: Prefix must be longer than 1 character");
1026  return;
1027  }
1028 
1029  for (int i = 0; i < prefix.count(); ++i) {
1030  if (!prefix.at(i).isLetterOrNumber()) {
1031  qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
1032  return;
1033  }
1034  }
1035 
1036  QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
1038  if (searchPaths.isEmpty()) {
1039  paths.remove(prefix);
1040  } else {
1041  paths.insert(prefix, searchPaths);
1042  }
1043 }
1044 
1055 void QDir::addSearchPath(const QString &prefix, const QString &path)
1056 {
1057  if (path.isEmpty())
1058  return;
1059 
1060  QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
1062 }
1063 
1074 QStringList QDir::searchPaths(const QString &prefix)
1075 {
1076  QReadLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
1078 }
1079 
1080 #endif // QT_BUILD_CORE_LIB
1081 
1085 QDir::Filters QDir::filter() const
1086 {
1087  const QDirPrivate* d = d_ptr.constData();
1088  return d->filters;
1089 }
1090 
1171 {
1172  QDirPrivate* d = d_ptr.data();
1173  d->initFileEngine();
1174  d->clearFileLists();
1175 
1176  d->filters = filters;
1177 }
1178 
1184 QDir::SortFlags QDir::sorting() const
1185 {
1186  const QDirPrivate* d = d_ptr.constData();
1187  return d->sort;
1188 }
1189 
1231 void QDir::setSorting(SortFlags sort)
1232 {
1233  QDirPrivate* d = d_ptr.data();
1234  d->initFileEngine();
1235  d->clearFileLists();
1236 
1237  d->sort = sort;
1238 }
1239 
1248 {
1249  const QDirPrivate* d = d_ptr.constData();
1250  d->initFileLists(*this);
1251  return d->files.count();
1252 }
1253 
1262 {
1263  const QDirPrivate* d = d_ptr.constData();
1264  d->initFileLists(*this);
1265  return d->files[pos];
1266 }
1267 
1290 QStringList QDir::entryList(Filters filters, SortFlags sort) const
1291 {
1292  const QDirPrivate* d = d_ptr.constData();
1293  return entryList(d->nameFilters, filters, sort);
1294 }
1295 
1296 
1317 {
1318  const QDirPrivate* d = d_ptr.constData();
1319  return entryInfoList(d->nameFilters, filters, sort);
1320 }
1321 
1339  SortFlags sort) const
1340 {
1341  const QDirPrivate* d = d_ptr.constData();
1342 
1343  if (filters == NoFilter)
1344  filters = d->filters;
1345 #ifdef QT3_SUPPORT
1346  if (d->matchAllDirs)
1347  filters |= AllDirs;
1348 #endif
1349  if (sort == NoSort)
1350  sort = d->sort;
1351 
1352  if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
1353  d->initFileLists(*this);
1354  return d->files;
1355  }
1356 
1357  QFileInfoList l;
1359  while (it.hasNext()) {
1360  it.next();
1361  l.append(it.fileInfo());
1362  }
1363  QStringList ret;
1364  d->sortFileList(sort, l, &ret, 0);
1365  return ret;
1366 }
1367 
1385  SortFlags sort) const
1386 {
1387  const QDirPrivate* d = d_ptr.constData();
1388 
1389  if (filters == NoFilter)
1390  filters = d->filters;
1391 #ifdef QT3_SUPPORT
1392  if (d->matchAllDirs)
1393  filters |= AllDirs;
1394 #endif
1395  if (sort == NoSort)
1396  sort = d->sort;
1397 
1398  if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
1399  d->initFileLists(*this);
1400  return d->fileInfos;
1401  }
1402 
1403  QFileInfoList l;
1405  while (it.hasNext()) {
1406  it.next();
1407  l.append(it.fileInfo());
1408  }
1409  QFileInfoList ret;
1410  d->sortFileList(sort, l, 0, &ret);
1411  return ret;
1412 }
1413 
1423 // ### Qt5: behaviour when directory already exists should be made consistent for mkdir and mkpath
1424 bool QDir::mkdir(const QString &dirName) const
1425 {
1426  const QDirPrivate* d = d_ptr.constData();
1427 
1428  if (dirName.isEmpty()) {
1429  qWarning("QDir::mkdir: Empty or null file name(s)");
1430  return false;
1431  }
1432 
1433  QString fn = filePath(dirName);
1434  if (d->fileEngine.isNull())
1436  return d->fileEngine->mkdir(fn, false);
1437 }
1438 
1448 bool QDir::rmdir(const QString &dirName) const
1449 {
1450  const QDirPrivate* d = d_ptr.constData();
1451 
1452  if (dirName.isEmpty()) {
1453  qWarning("QDir::rmdir: Empty or null file name(s)");
1454  return false;
1455  }
1456 
1457  QString fn = filePath(dirName);
1458  if (d->fileEngine.isNull())
1460 
1461  return d->fileEngine->rmdir(fn, false);
1462 }
1463 
1476 // ### Qt5: behaviour when directory already exists should be made consistent for mkdir and mkpath
1477 bool QDir::mkpath(const QString &dirPath) const
1478 {
1479  const QDirPrivate* d = d_ptr.constData();
1480 
1481  if (dirPath.isEmpty()) {
1482  qWarning("QDir::mkpath: Empty or null file name(s)");
1483  return false;
1484  }
1485 
1486  QString fn = filePath(dirPath);
1487  if (d->fileEngine.isNull())
1489  return d->fileEngine->mkdir(fn, true);
1490 }
1491 
1503 bool QDir::rmpath(const QString &dirPath) const
1504 {
1505  const QDirPrivate* d = d_ptr.constData();
1506 
1507  if (dirPath.isEmpty()) {
1508  qWarning("QDir::rmpath: Empty or null file name(s)");
1509  return false;
1510  }
1511 
1512  QString fn = filePath(dirPath);
1513  if (d->fileEngine.isNull())
1515  return d->fileEngine->rmdir(fn, true);
1516 }
1517 
1527 bool QDir::isReadable() const
1528 {
1529  const QDirPrivate* d = d_ptr.constData();
1530 
1531  if (d->fileEngine.isNull()) {
1534 
1535  return (d->metaData.permissions() & QFile::ReadUser) != 0;
1536  }
1537 
1538  const QAbstractFileEngine::FileFlags info =
1541  if (!(info & QAbstractFileEngine::DirectoryType))
1542  return false;
1543  return info & QAbstractFileEngine::ReadUserPerm;
1544 }
1545 
1560 bool QDir::exists() const
1561 {
1562  return d_ptr->exists();
1563 }
1564 
1577 bool QDir::isRoot() const
1578 {
1579  if (d_ptr->fileEngine.isNull())
1580  return d_ptr->dirEntry.isRoot();
1582 }
1583 
1615 bool QDir::isRelative() const
1616 {
1617  if (d_ptr->fileEngine.isNull())
1618  return d_ptr->dirEntry.isRelative();
1619  return d_ptr->fileEngine->isRelativePath();
1620 }
1621 
1622 
1631 {
1632  const QDirPrivate *d = d_ptr.constData();
1634  if (!d->fileEngine.isNull()) {
1636  if (QDir::isRelativePath(absolutePath))
1637  return false;
1638 
1639  dir.reset(new QDirPrivate(*d_ptr.constData()));
1640  dir->setPath(absolutePath);
1641  } else { // native FS
1642  d->resolveAbsoluteEntry();
1643  dir.reset(new QDirPrivate(*d_ptr.constData()));
1644  dir->setPath(d->absoluteDirEntry.filePath());
1645  }
1646  d_ptr = dir.take(); // actually detach
1647  return true;
1648 }
1649 
1659 bool QDir::operator==(const QDir &dir) const
1660 {
1661  const QDirPrivate *d = d_ptr.constData();
1662  const QDirPrivate *other = dir.d_ptr.constData();
1663 
1664  if (d == other)
1665  return true;
1666  Qt::CaseSensitivity sensitive;
1667  if (d->fileEngine.isNull() || other->fileEngine.isNull()) {
1668  if (d->fileEngine.data() != other->fileEngine.data()) // one is native, the other is a custom file-engine
1669  return false;
1670 
1672  } else {
1673  if (d->fileEngine->caseSensitive() != other->fileEngine->caseSensitive())
1674  return false;
1676  }
1677 
1678  if (d->filters == other->filters
1679  && d->sort == other->sort
1680  && d->nameFilters == other->nameFilters) {
1681 
1682  // Assume directories are the same if path is the same
1683  if (d->dirEntry.filePath() == other->dirEntry.filePath())
1684  return true;
1685 
1686  if (exists()) {
1687  if (!dir.exists())
1688  return false; //can't be equal if only one exists
1689  // Both exist, fallback to expensive canonical path computation
1690  return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
1691  } else {
1692  if (dir.exists())
1693  return false; //can't be equal if only one exists
1694  // Neither exists, compare absolute paths rather than canonical (which would be empty strings)
1695  d->resolveAbsoluteEntry();
1696  other->resolveAbsoluteEntry();
1697  return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
1698  }
1699  }
1700  return false;
1701 }
1702 
1708 {
1709  d_ptr = dir.d_ptr;
1710  return *this;
1711 }
1712 
1725 {
1726  d_ptr->setPath(path);
1727  return *this;
1728 }
1729 
1752 {
1753  if (fileName.isEmpty()) {
1754  qWarning("QDir::remove: Empty or null file name");
1755  return false;
1756  }
1757  return QFile::remove(filePath(fileName));
1758 }
1759 
1771 bool QDir::rename(const QString &oldName, const QString &newName)
1772 {
1773  if (oldName.isEmpty() || newName.isEmpty()) {
1774  qWarning("QDir::rename: Empty or null file name(s)");
1775  return false;
1776  }
1777 
1778  QFile file(filePath(oldName));
1779  if (!file.exists())
1780  return false;
1781  return file.rename(filePath(newName));
1782 }
1783 
1794 bool QDir::exists(const QString &name) const
1795 {
1796  if (name.isEmpty()) {
1797  qWarning("QDir::exists: Empty or null file name");
1798  return false;
1799  }
1800  return QFile::exists(filePath(name));
1801 }
1802 
1813 {
1814 #ifdef QT_NO_FSFILEENGINE
1815  return QFileInfoList();
1816 #else
1817  return QFSFileEngine::drives();
1818 #endif
1819 }
1820 
1832 {
1833 #if defined (Q_FS_FAT) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
1834  return QLatin1Char('\\');
1835 #elif defined(Q_OS_UNIX)
1836  return QLatin1Char('/');
1837 #elif defined (Q_OS_MAC)
1838  return QLatin1Char(':');
1839 #else
1840  return QLatin1Char('/');
1841 #endif
1842 }
1843 
1851 bool QDir::setCurrent(const QString &path)
1852 {
1854 }
1855 
1876 {
1878 }
1879 
1943 {
1944  return QFileSystemEngine::homePath();
1945 }
1946 
1988 {
1989  return QFileSystemEngine::tempPath();
1990 }
1991 
2017 {
2018  return QFileSystemEngine::rootPath();
2019 }
2020 
2034 #ifndef QT_NO_REGEXP
2035 
2048 {
2049  for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) {
2051  if (rx.exactMatch(fileName))
2052  return true;
2053  }
2054  return false;
2055 }
2056 
2066 {
2067  return match(nameFiltersFromString(filter), fileName);
2068 }
2069 #endif // QT_NO_REGEXP
2070 
2083 {
2084  if (path.isEmpty())
2085  return path;
2086  QString name = path;
2087  QChar dir_separator = separator();
2088  if (dir_separator != QLatin1Char('/'))
2089  name.replace(dir_separator, QLatin1Char('/'));
2090 
2091  int used = 0, levels = 0;
2092  const int len = name.length();
2093  QVarLengthArray<QChar> outVector(len);
2094  QChar *out = outVector.data();
2095 
2096  const QChar *p = name.unicode();
2097  for (int i = 0, last = -1, iwrite = 0; i < len; ++i) {
2098  if (p[i] == QLatin1Char('/')) {
2099  while (i+1 < len && p[i+1] == QLatin1Char('/')) {
2100 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths
2101  if (!i)
2102  break;
2103 #endif
2104  i++;
2105  }
2106  bool eaten = false;
2107  if (i+1 < len && p[i+1] == QLatin1Char('.')) {
2108  int dotcount = 1;
2109  if (i+2 < len && p[i+2] == QLatin1Char('.'))
2110  dotcount++;
2111  if (i == len - dotcount - 1) {
2112  if (dotcount == 1) {
2113  break;
2114  } else if (levels) {
2115  if (last == -1) {
2116  for (int i2 = iwrite-1; i2 >= 0; i2--) {
2117  if (out[i2] == QLatin1Char('/')) {
2118  last = i2;
2119  break;
2120  }
2121  }
2122  }
2123  used -= iwrite - last - 1;
2124  break;
2125  }
2126  } else if (p[i+dotcount+1] == QLatin1Char('/')) {
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--) {
2130  if (out[i2] == QLatin1Char('/')) {
2131  eaten = true;
2132  last = i2;
2133  break;
2134  }
2135  }
2136  } else {
2137  eaten = true;
2138  }
2139  if (eaten) {
2140  levels--;
2141  used -= iwrite - last;
2142  iwrite = last;
2143  last = -1;
2144  }
2145  } else if (dotcount == 2 && i > 0 && p[i - 1] != QLatin1Char('.')) {
2146  eaten = true;
2147  used -= iwrite - qMax(0, last);
2148  iwrite = qMax(0, last);
2149  last = -1;
2150  ++i;
2151  } else if (dotcount == 1) {
2152  eaten = true;
2153  }
2154  if (eaten)
2155  i += dotcount;
2156  } else {
2157  levels++;
2158  }
2159  } else if (last != -1 && iwrite - last == 1) {
2160 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
2161  eaten = (iwrite > 2);
2162 #else
2163  eaten = true;
2164 #endif
2165  last = -1;
2166  } else if (last != -1 && i == len-1) {
2167  eaten = true;
2168  } else {
2169  levels++;
2170  }
2171  if (!eaten)
2172  last = i - (i - iwrite);
2173  else
2174  continue;
2175  } else if (!i && p[i] == QLatin1Char('.')) {
2176  int dotcount = 1;
2177  if (len >= 1 && p[1] == QLatin1Char('.'))
2178  dotcount++;
2179  if (len >= dotcount && p[dotcount] == QLatin1Char('/')) {
2180  if (dotcount == 1) {
2181  i++;
2182  while (i+1 < len-1 && p[i+1] == QLatin1Char('/'))
2183  i++;
2184  continue;
2185  }
2186  }
2187  }
2188  out[iwrite++] = p[i];
2189  used++;
2190  }
2191 
2192  QString ret = (used == len ? name : QString(out, used));
2193  // Strip away last slash except for root directories
2194  if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
2195 #if defined (Q_OS_WIN) || defined (Q_OS_SYMBIAN)
2196  if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':')))
2197 #endif
2198  ret.chop(1);
2199  }
2200 
2201  return ret;
2202 }
2203 
2211 {
2212  return QFileInfo(path).isRelative();
2213 }
2214 
2218 void QDir::refresh() const
2219 {
2220  QDirPrivate *d = const_cast<QDir*>(this)->d_ptr.data();
2221  d->metaData.clear();
2222  d->initFileEngine();
2223  d->clearFileLists();
2224 }
2225 
2237 {
2238  return QDirPrivate::splitFilters(nameFilter);
2239 }
2240 
2299 #ifdef QT3_SUPPORT
2300 
2309 bool QDir::matchAllDirs() const
2310 {
2311  const QDirPrivate* d = d_ptr.constData();
2312  return d->matchAllDirs;
2313 }
2314 
2315 
2324 void QDir::setMatchAllDirs(bool on)
2325 {
2326  QDirPrivate* d = d_ptr.data();
2327  d->initFileEngine();
2328  d->clearFileLists();
2329 
2330  d->matchAllDirs = on;
2331 }
2332 
2336 QString QDir::nameFilter() const
2337 {
2338  const QDirPrivate* d = d_ptr.constData();
2339  return nameFilters().join(QString(d->filterSepChar));
2340 }
2341 
2362 void QDir::setNameFilter(const QString &nameFilter)
2363 {
2364  QDirPrivate* d = d_ptr.data();
2365  d->initFileEngine();
2366  d->clearFileLists();
2367 
2368  d->filterSepChar = QDirPrivate::getFilterSepChar(nameFilter);
2369  d->nameFilters = QDirPrivate::splitFilters(nameFilter, d->filterSepChar);
2370 }
2371 
2473 #endif // QT3_SUPPORT
2474 
2475 #ifndef QT_NO_DEBUG_STREAM
2476 QDebug operator<<(QDebug debug, QDir::Filters filters)
2477 {
2478  QStringList flags;
2479  if (filters == QDir::NoFilter) {
2480  flags << QLatin1String("NoFilter");
2481  } else {
2482  if (filters & QDir::Dirs) flags << QLatin1String("Dirs");
2483  if (filters & QDir::AllDirs) flags << QLatin1String("AllDirs");
2484  if (filters & QDir::Files) flags << QLatin1String("Files");
2485  if (filters & QDir::Drives) flags << QLatin1String("Drives");
2486  if (filters & QDir::NoSymLinks) flags << QLatin1String("NoSymLinks");
2487  if (filters & QDir::NoDotAndDotDot) flags << QLatin1String("NoDotAndDotDot"); // ### Qt5: remove (because NoDotAndDotDot=NoDot|NoDotDot)
2488  if (filters & QDir::NoDot) flags << QLatin1String("NoDot");
2489  if (filters & QDir::NoDotDot) flags << QLatin1String("NoDotDot");
2490  if ((filters & QDir::AllEntries) == QDir::AllEntries) flags << QLatin1String("AllEntries");
2491  if (filters & QDir::Readable) flags << QLatin1String("Readable");
2492  if (filters & QDir::Writable) flags << QLatin1String("Writable");
2493  if (filters & QDir::Executable) flags << QLatin1String("Executable");
2494  if (filters & QDir::Modified) flags << QLatin1String("Modified");
2495  if (filters & QDir::Hidden) flags << QLatin1String("Hidden");
2496  if (filters & QDir::System) flags << QLatin1String("System");
2497  if (filters & QDir::CaseSensitive) flags << QLatin1String("CaseSensitive");
2498  }
2499  debug << "QDir::Filters(" << qPrintable(flags.join(QLatin1String("|"))) << ')';
2500  return debug;
2501 }
2502 
2503 static QDebug operator<<(QDebug debug, QDir::SortFlags sorting)
2504 {
2505  if (sorting == QDir::NoSort) {
2506  debug << "QDir::SortFlags(NoSort)";
2507  } else {
2508  QString type;
2509  if ((sorting & 3) == QDir::Name) type = QLatin1String("Name");
2510  if ((sorting & 3) == QDir::Time) type = QLatin1String("Time");
2511  if ((sorting & 3) == QDir::Size) type = QLatin1String("Size");
2512  if ((sorting & 3) == QDir::Unsorted) type = QLatin1String("Unsorted");
2513 
2514  QStringList flags;
2515  if (sorting & QDir::DirsFirst) flags << QLatin1String("DirsFirst");
2516  if (sorting & QDir::DirsLast) flags << QLatin1String("DirsLast");
2517  if (sorting & QDir::IgnoreCase) flags << QLatin1String("IgnoreCase");
2518  if (sorting & QDir::LocaleAware) flags << QLatin1String("LocaleAware");
2519  if (sorting & QDir::Type) flags << QLatin1String("Type");
2520  debug << "QDir::SortFlags(" << qPrintable(type)
2521  << '|'
2522  << qPrintable(flags.join(QLatin1String("|"))) << ')';
2523  }
2524  return debug;
2525 }
2526 
2527 QDebug operator<<(QDebug debug, const QDir &dir)
2528 {
2529  debug.maybeSpace() << "QDir(" << dir.path()
2530  << ", nameFilters = {"
2531  << qPrintable(dir.nameFilters().join(QLatin1String(",")))
2532  << "}, "
2533  << dir.sorting()
2534  << ','
2535  << dir.filter()
2536  << ')';
2537  return debug.space();
2538 }
2539 #endif // QT_NO_DEBUG_STREAM
2540 
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.
Definition: qdir.h:58
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const
This function should return the set of OR&#39;d flags that are true for the file engine&#39;s file...
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
Definition: qdir.cpp:1477
~QDir()
Destroys the QDir object frees up its resources.
Definition: qdir.cpp:570
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
Definition: qfile.cpp:766
int type
Definition: qmetatype.cpp:239
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
bool operator()(const QDirSortItem &, const QDirSortItem &)
Definition: qdir.cpp:231
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
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...
Definition: qdir.cpp:2047
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString operator[](int) const
Returns the file name at position pos in the list of file names.
Definition: qdir.cpp:1261
QList< QFileInfo > QFileInfoList
Definition: qfileinfo.h:197
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.
Definition: qdir.cpp:701
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
Definition: qdir.cpp:561
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
virtual QString fileName(FileName file=DefaultName) const
Return the file engine&#39;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.
Definition: qdir.h:192
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...
Definition: qchar.h:251
#define it(className, varName)
static QStringList splitFilters(const QString &nameFilter, QChar sep=0)
Definition: qdir.cpp:158
QFile::Permissions permissions() const
void setPath(const QString &path)
Sets the path of the directory to path.
Definition: qdir.cpp:590
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)
Definition: qdir.cpp:168
T * data()
Returns a pointer to the shared data object.
Definition: qshareddata.h:82
static QChar getFilterSepChar(const QString &nameFilter)
Definition: qdir.cpp:148
SortFlags sorting() const
Returns the value set by setSorting()
Definition: qdir.cpp:1184
bool isRelative() const
Returns true if the directory path is relative; otherwise returns false.
Definition: qdir.cpp:1615
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
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)
Definition: qdir.cpp:71
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
QDirSortItemComparator(int flags)
Definition: qdir.cpp:227
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
bool mkdir(const QString &dirName) const
Creates a sub-directory called dirName.
Definition: qdir.cpp:1424
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
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.
Definition: qlist.h:891
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
QStringList files
Definition: qdir_p.h:88
The QDirIterator class provides an iterator for directory entrylists.
Definition: qdiriterator.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
uint count() const
Returns the total number of directories and files in the directory.
Definition: qdir.cpp:1247
void initFileEngine()
Definition: qdir.cpp:338
QFileInfo fileInfo() const
Returns a QFileInfo for the current directory entry.
bool exists() const
Definition: qdir.cpp:131
QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition: qdir.cpp:2476
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
bool fileListsInitialized
Definition: qdir_p.h:87
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
bool exists() const
Returns true if the directory exists; otherwise returns false.
Definition: qdir.cpp:1560
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setNameFilters(const QStringList &nameFilters)
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nam...
Definition: qdir.cpp:966
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QFileInfo item
Definition: qdir.cpp:219
static QFileSystemEntry currentPath()
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
void refresh() const
Refreshes the directory information.
Definition: qdir.cpp:2218
bool cdUp()
Changes directory by moving one directory up from the QDir&#39;s current directory.
Definition: qdir.cpp:937
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool rename(const QString &oldName, const QString &newName)
Renames a file or directory from oldName to newName, and returns true if successful; otherwise return...
Definition: qdir.cpp:1771
bool isReadable() const
Returns true if the directory is readable and we can open files by name; otherwise returns false...
Definition: qdir.cpp:1527
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
static void addSearchPath(const QString &prefix, const QString &path)
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
static QT_DEPRECATED QString convertSeparators(const QString &pathName)
Use QDir::toNativeSeparators() instead.
Definition: qdir.cpp:788
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.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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.
Definition: qdir.cpp:619
QStringList nameFilters() const
Returns the string list set by setNameFilters()
Definition: qdir.cpp:945
bool rmpath(const QString &dirPath) const
Removes the directory path dirPath.
Definition: qdir.cpp:1503
const char * name
static void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *)
Definition: qdir.cpp:294
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString fileName() const
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
Definition: qdatetime.cpp:2914
static void addSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
Definition: qresource.cpp:577
Q_CORE_EXPORT void qWarning(const char *,...)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
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)
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
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().
Definition: qdir.cpp:1316
QDebug & maybeSpace()
Writes a space character to the debug stream, depending on the last character sent to the stream...
Definition: qdebug.h:93
bool hasFlags(MetaDataFlags flags) const
static QFileInfoList drives()
Returns a list of the root directories on this system.
Definition: qdir.cpp:1812
void clear()
Removes all items from the list.
Definition: qlist.h:764
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...
Definition: qdir.cpp:2082
The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects...
bool cd(const QString &dirName)
Changes the QDir&#39;s directory to dirName.
Definition: qdir.cpp:880
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
int count() const
Definition: qstring.h:103
int localeAwareCompare(const QString &s) const
Definition: qstring.cpp:5197
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.
Definition: qdir.cpp:1707
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...
Definition: qchar.cpp:1490
static QString tempPath()
Returns the absolute path of the system&#39;s temporary directory.
Definition: qdir.cpp:1987
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
int remove(const Key &key)
Removes all the items that have the key key from the map.
Definition: qmap.h:662
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...
Definition: qstring.cpp:3706
void setSorting(SortFlags sort)
Sets the sort order used by entryList() and entryInfoList().
Definition: qdir.cpp:1231
static bool setCurrentPath(const QFileSystemEntry &entry)
CaseSensitivity
Definition: qnamespace.h:1451
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
Definition: qstring.cpp:5037
qint64 size() const
Returns the file size in bytes.
Definition: qfileinfo.cpp:1248
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QString trimmed(QString source)
Definition: generator.cpp:233
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
QString filename_cache
Definition: qdir.cpp:217
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...
Definition: qstring.cpp:4188
QStringList nameFilters
Definition: qdir_p.h:76
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QDir::SortFlags sort
Definition: qdir_p.h:77
QString relativeFilePath(const QString &fileName) const
Returns the path to fileName relative to the directory.
Definition: qdir.cpp:722
static QStringList nameFiltersFromString(const QString &nameFilter)
Returns a list of name filters from the given nameFilter.
Definition: qdir.cpp:2236
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool rmdir(const QString &dirName) const
Removes the directory specified by dirName.
Definition: qdir.cpp:1448
Filters filter() const
Returns the value set by setFilter()
Definition: qdir.cpp:1085
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isRelative() const
Returns true if the file path name is relative, otherwise returns false if the path is absolute (e...
Definition: qfileinfo.cpp:642
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QString canonicalPath() const
Returns the canonical path, i.e.
Definition: qdir.cpp:642
QFactoryLoader * l
void clearFileLists()
Definition: qdir.cpp:187
QDir::Filters filters
Definition: qdir_p.h:78
static QStringList searchPaths(const QString &prefix)
static QString rootPath()
Returns the absolute path of the root directory.
Definition: qdir.cpp:2016
QString filePath() const
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
Definition: qregexp.cpp:4094
QFileSystemMetaData metaData
Definition: qdir_p.h:93
bool remove(const QString &fileName)
Removes the file, fileName.
Definition: qdir.cpp:1751
bool isRelative() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
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...
Definition: qstring.cpp:6526
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 &#39;/&#39; as file separator.
Definition: qdir.cpp:848
QString path() const
Returns the path.
Definition: qdir.cpp:605
void resolveAbsoluteEntry() const
Definition: qdir.cpp:194
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678
QFileSystemEntry absoluteDirEntry
Definition: qdir_p.h:92
bool operator==(const QDir &dir) const
Returns true if directory dir and this directory have the same path and their sort and filter setting...
Definition: qdir.cpp:1659
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QString dirName() const
Returns the name of the directory; this is not the same as the path, e.g.
Definition: qdir.cpp:663
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
bool isRoot() const
Returns true if the directory is the root directory; otherwise returns false.
Definition: qdir.cpp:1577
#define qPrintable(string)
Definition: qglobal.h:1750
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
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...
Definition: qdir.cpp:1290
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void initFileLists(const QDir &dir) const
Definition: qdir.cpp:324
static void addResourceSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
Definition: qdir.cpp:989
QFileInfoList fileInfos
Definition: qdir_p.h:89
void setFilter(Filters filter)
Sets the filter used by entryList() and entryInfoList() to filters.
Definition: qdir.cpp:1170
QString suffix_cache
Definition: qdir.cpp:218
static bool setCurrent(const QString &path)
Sets the application&#39;s current working directory to path.
Definition: qdir.cpp:1851
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681
QMap< QString, QStringList > dirSearchPaths
bool makeAbsolute()
Converts the directory path to an absolute path.
Definition: qdir.cpp:1630
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
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)
Definition: qdir.cpp:89
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942
QDateTime lastModified() const
Returns the date and time when the file was last modified.
Definition: qfileinfo.cpp:1296