📄 qdir.cpp
字号:
if (name.isEmpty()) { qWarning("QDir::exists: Empty or null file name"); return false; } QString tmp = filePath(name); return QFile::exists(tmp);}/*! Returns a list of the root directories on this system. On Windows this returns a number of QFileInfo objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").*/QFileInfoList QDir::drives(){ return QFSFileEngine::drives();}/*! Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows. You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use convertSeparators().*/QChar QDir::separator(){#if defined(Q_OS_UNIX) return QLatin1Char('/');#elif defined (Q_FS_FAT) || defined(Q_WS_WIN) return QLatin1Char('\\');#elif defined (Q_OS_MAC) return QLatin1Char(':');#else return QLatin1Char('/');#endif}/*! Sets the application's current working directory to \a path. Returns true if the directory was successfully changed; otherwise returns false. \sa current() currentPath() home() root() temp()*/bool QDir::setCurrent(const QString &path){ return QFSFileEngine::setCurrentPath(path);}/*! \fn QDir QDir::current() Returns the absolute path of the application's current directory. See currentPath() for details. \sa drives() homePath() rootPath() tempPath()*//*! Returns the absolute path of the application's current directory. \sa current() drives() homePath() rootPath() tempPath()*/QString QDir::currentPath(){ return QFSFileEngine::currentPath();}/*! \fn QDir QDir::home() Returns the user's home directory. See homePath() for details. \sa drives() currentPath() rootPath() tempPath()*//*! Returns the user's home directory. Under Windows the \c HOME environment variable is used. If this does not exist the \c USERPROFILE environment variable is used. If that does not exist the path is formed by concatenating the \c HOMEDRIVE and \c HOMEPATH environment variables. If they don't exist the rootPath() is used (this uses the \c SystemDrive environment variable). If none of these exist "C:\" is used. Under non-Windows operating systems the \c HOME environment variable is used if it exists, otherwise rootPath() is used. \sa home() drives() currentPath() rootPath() tempPath()*/QString QDir::homePath(){ return QFSFileEngine::homePath();}/*! \fn QDir QDir::temp() Returns the system's temporary directory. See tempPath() for details. \sa drives() currentPath() homePath() rootPath()*//*! Returns the system's temporary directory. On Unix/Linux systems this is usually \c{/tmp}; on Windows this is usually the path in the \c TEMP or \c TMP environment variable. \sa temp() drives() currentPath() homePath() rootPath()*/QString QDir::tempPath(){ return QFSFileEngine::tempPath();}/*! \fn QDir QDir::root() Returns the root directory. See rootPath() for details. \sa drives() current() home() temp()*//*! Returns the absolute path for the root directory. For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/". \sa root() drives() currentPath() homePath() tempPath()*/QString QDir::rootPath(){ return QFSFileEngine::rootPath();}#ifndef QT_NO_REGEXP/*! \overload Returns true if the \a fileName matches any of the wildcard (glob) patterns in the list of \a filters; otherwise returns false. The matching is case insensitive. \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()*/bool QDir::match(const QStringList &filters, const QString &fileName){ for(QStringList::ConstIterator sit = filters.begin(); sit != filters.end(); ++sit) { QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard); if (rx.exactMatch(fileName)) return true; } return false;}/*! Returns true if the \a fileName matches the wildcard (glob) pattern \a filter; otherwise returns false. The \a filter may contain multiple patterns separated by spaces or semicolons. The matching is case insensitive. \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()*/bool QDir::match(const QString &filter, const QString &fileName){ return match(nameFiltersFromString(filter), fileName);}#endif/*! Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path, \a path. Symbolic links are kept. This function does not return the canonical path, but rather the simplest version of the input. For example, "./local" becomes "local", "local/../bin" becomes "bin" and "/local/usr/../bin" becomes "/local/bin". \sa absolutePath() canonicalPath()*/QString QDir::cleanPath(const QString &path){ if (path.isEmpty()) return path; QString name = path; QChar dir_separator = separator(); if(dir_separator != QLatin1Char('/')) name.replace(dir_separator, QLatin1Char('/')); int used = 0, levels = 0; const int len = name.length(); QVector<QChar> out(len); const QChar *p = name.unicode(); for(int i = 0, last = -1, iwrite = 0; i < len; i++) { if(p[i] == QLatin1Char('/')) { while(i < len-1 && p[i+1] == QLatin1Char('/')) {#ifdef Q_OS_WIN //allow unc paths if(!i) break;#endif i++; } bool eaten = false; if(i < len - 1 && p[i+1] == QLatin1Char('.')) { int dotcount = 1; if(i < len - 2 && p[i+2] == QLatin1Char('.')) dotcount++; if(i == len - dotcount - 1) { if(dotcount == 1) { break; } else if(levels) { if(last == -1) { for(int i2 = iwrite-1; i2 >= 0; i2--) { if(out[i2] == QLatin1Char('/')) { last = i2; break; } } } used -= iwrite - last - 1; break; } } else if(p[i+dotcount+1] == QLatin1Char('/')) { if(dotcount == 2 && levels) { if(last == -1 || iwrite - last == 1) { for(int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) { if(out[i2] == QLatin1Char('/')) { eaten = true; last = i2; break; } } } else { eaten = true; } if(eaten) { levels--; used -= iwrite - last; iwrite = last; last = -1; } } else if(dotcount == 1) { eaten = true; } if(eaten) i += dotcount; } else { levels++; } } else if(last != -1 && iwrite - last == 1) {#ifdef Q_OS_WIN eaten = (iwrite > 2);#else eaten = true;#endif last = -1; } else if(last != -1 && i == len-1) { eaten = true; } else { levels++; } if(!eaten) last = i - (i - iwrite); else continue; } else if(!i && p[i] == QLatin1Char('.')) { int dotcount = 1; if(len >= 1 && p[1] == QLatin1Char('.')) dotcount++; if(len >= dotcount && p[dotcount] == QLatin1Char('/')) { if(dotcount == 1) { i++; while(i+1 < len-1 && p[i+1] == QLatin1Char('/')) i++; continue; } } } out[iwrite++] = p[i]; used++; } QString ret; if(used == len) ret = name; else ret = QString(out.data(), used); // Strip away last slash except for root directories if (ret.endsWith(QLatin1Char('/')) && !(ret.size() == 1 || (ret.size() == 3 && ret.at(1) == QLatin1Char(':')))) ret = ret.left(ret.length() - 1); return ret;}/*! Returns true if \a path is relative; returns false if it is absolute. \sa isRelative() isAbsolutePath() makeAbsolute()*/bool QDir::isRelativePath(const QString &path){ return QFileInfo(path).isRelative();}/*! Refreshes the directory information.*/void QDir::refresh() const{ Q_D(const QDir); d->data->clear();}/*! \internal Returns a list of name filters from the given \a nameFilter. (If there is more than one filter, each pair of filters is separated by a space or by a semicolon.)*/QStringList QDir::nameFiltersFromString(const QString &nameFilter){ return QDirPrivate::splitFilters(nameFilter);}/*! \macro void Q_INIT_RESOURCE(name) \relates QDir Initializes the resources specified by the \c .qrc file with the specified base \a name. Normally, Qt resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro is necessary on some platforms for resources stored in a static library. For example, if your application's resources are listed in a file called \c myapp.qrc, you can ensure that the resources are initialized at startup by adding this line to your \c main() function: \code Q_INIT_RESOURCE(myapp); \endcode \sa Q_CLEANUP_RESOURCE(), {The Qt Resource System}*//*! \since 4.1 \macro void Q_CLEANUP_RESOURCE(name) \relates QDir Unloads the resources specified by the \c .qrc file with the base name \a name. Normally, Qt resources are unloaded automatically when the application terminates, but if the resources are located in a plugin that is being unloaded, call Q_CLEANUP_RESOURCE() to force removal of your resources. Example: \code Q_CLEANUP_RESOURCE(myapp); \endcode \sa Q_INIT_RESOURCE(), {The Qt Resource System}*/#ifdef QT3_SUPPORT/*! \fn bool QDir::matchAllDirs() const Use filter() & AllDirs instead.*/bool QDir::matchAllDirs() const{ Q_D(const QDir); return d->matchAllDirs;}/*! \fn void QDir::setMatchAllDirs(bool on) Use setFilter() instead.*/void QDir::setMatchAllDirs(bool on){ Q_D(QDir); d->matchAllDirs = on;}/*! Use nameFilters() instead.*/QString QDir::nameFilter() const{ Q_D(const QDir); return nameFilters().join(QString(d->filterSepChar));}/*! Use setNameFilters() instead. The \a nameFilter is a wildcard (globbing) filter that understands "*" and "?" wildcards. (See \l{QRegExp wildcard matching}.) You may specify several filter entries, each separated by spaces or by semicolons. For example, if you want entryList() and entryInfoList() to list all files ending with either ".cpp" or ".h", you would use either dir.setNameFilters("*.cpp *.h") or dir.setNameFilters("*.cpp;*.h"). \oldcode QString filter = "*.cpp *.cxx *.cc"; dir.setNameFilter(filter); \newcode QString filter = "*.cpp *.cxx *.cc"; dir.setNameFilters(filter.split(' ')); \endcode*/void QDir::setNameFilter(const QString &nameFilter){ Q_D(QDir); d->filterSepChar = QDirPrivate::getFilterSepChar(nameFilter); setNameFilters(QDirPrivate::splitFilters(nameFilter, d->filterSepChar));}/*! \fn QString QDir::absPath() const Use absolutePath() instead.*//*! \fn QString QDir::absFilePath(const QString &fileName, bool acceptAbsPath) const Use absoluteFilePath(\a fileName) instead. The \a acceptAbsPath parameter is ignored.*//*! \fn bool QDir::mkdir(const QString &dirName, bool acceptAbsPath) const Use mkdir(\a dirName) instead. The \a acceptAbsPath parameter is ignored.*//*! \fn bool QDir::rmdir(const QString &dirName, bool acceptAbsPath) const Use rmdir(\a dirName) instead. The \a acceptAbsPath parameter is ignored.*//*! \fn QStringList QDir::entryList(const QString &nameFilter, Filters filters, SortFlags sort) const Use the overload that takes a name filter string list as first argument instead.*//*! \fn QFileInfoList QDir::entryInfoList(const QString &nameFilter, Filters filters, SortFlags sort) const Use the overload that takes a name filter string list as first argument instead.*//*! \fn void QDir::convertToAbs() Use makeAbsolute() instead.*//*! \fn QString QDir::cleanDirPath(const QString &name) Use cleanPath() instead.*//*! \typedef QDir::FilterSpec Use QDir::Filters instead.*//*! \typedef QDir::SortSpec Use QDir::SortFlags instead.*/#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -