?? qdir.cpp
字號:
return true; QString newPath = d->data->path; if (isAbsolutePath(dirName)) { newPath = cleanPath(dirName); } else { if (isRoot()) { if (dirName == QLatin1String("..")) return false; } else { newPath += QLatin1Char('/'); } newPath += dirName; if (dirName.indexOf(QLatin1Char('/')) >= 0 || d->data->path == QLatin1String(".") || dirName == QLatin1String("..")) { newPath = cleanPath(newPath); /* If newPath starts with .., we convert it to absolute to avoid infinite looping on QDir dir("."); while (dir.cdUp()) ; */ if (newPath.startsWith(QLatin1String(".."))) { newPath = QFileInfo(newPath).absoluteFilePath(); } } } { QFileInfo fi(newPath); if (!(fi.exists() && fi.isDir())) return false; } d->setPath(newPath); refresh(); return true;}/*! Changes directory by moving one directory up from the QDir's current directory. Returns true if the new directory exists and is readable; otherwise returns false. Note that the logical cdUp() operation is not performed if the new directory does not exist. \sa cd(), isReadable(), exists(), path()*/bool QDir::cdUp(){ return cd(QString::fromLatin1(".."));}/*! Returns the string list set by setNameFilters()*/QStringList QDir::nameFilters() const{ Q_D(const QDir); return d->data->nameFilters;}/*! Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by \a nameFilters. Each name filter is a wildcard (globbing) filter that understands \c{*} and \c{?} wildcards. (See \l{QRegExp wildcard matching}.) For example, the following code sets three name filters on a QDir to ensure that only files with extensions typically used for C++ source files are listed: \quotefromfile snippets/qdir-namefilters/main.cpp \skipto QStringList \printuntil setNameFilters \sa nameFilters(), setFilter()*/void QDir::setNameFilters(const QStringList &nameFilters){ Q_D(QDir); d->detach(); d->data->nameFilters = nameFilters;}/*! Adds \a path to the search paths searched in to find resources that are not specified with an absolute path. The default search path is to search only in the root (\c{:/}). \sa {The Qt Resource System}, QResource::addSearchPath()*/void QDir::addResourceSearchPath(const QString &path){#ifdef QT_BUILD_CORE_LIB QResource::addSearchPath(path);#else Q_UNUSED(path)#endif}/*! Returns the value set by setFilter()*/QDir::Filters QDir::filter() const{ Q_D(const QDir); return d->data->filters;}/*! \enum QDir::Filter This enum describes the filtering options available to QDir; e.g. for entryList() and entryInfoList(). The filter value is specified by combining values from the following list using the bitwise OR operator: \value Dirs List directories that match the filters. \value AllDirs List all directories; i.e. don't apply the filters to directory names. \value Files List files only. \value Drives List disk drives (ignored under Unix). \value NoSymLinks Do not list symbolic links (ignored by operating systems that don't support symbolic links). \value NoDotAndDotDot Do not list the special entries "." and "..". \value AllEntries List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System). \value Readable List files for which the application has read access. The Readable value needs to be combined with Dirs or Files. \value Writable List files for which the application has write access. The Writable value needs to be combined with Dirs or Files. \value Executable List files for which the application has execute access. The Executable value needs to be combined with Dirs or Files. \value Modified Only list files that have been modified (ignored under Unix). \value Hidden List hidden files (on Unix, files starting with a .). \value System List system files (on Unix, FIFOs, sockets and device files) \value CaseSensitive The filter should be case sensitive if the file system is case sensitive. \omitvalue DefaultFilter \omitvalue TypeMask \omitvalue All \omitvalue RWEMask \omitvalue AccessMask \omitvalue PermissionMask \omitvalue NoFilter Functions that use Filter enum values to filter lists of files and directories will include symbolic links to files and directories unless you set the NoSymLinks value. A default constructed QDir will not filter out files based on their permissions, so entryList() and entryInfoList() will return all files that are readable, writable, executable, or any combination of the three. This makes the default easy to write, and at the same time useful. For example, setting the \c Readable, \c Writable, and \c Files flags allows all files to be listed for which the application has read access, write access or both. If the \c Dirs and \c Drives flags are also included in this combination then all drives, directories, all files that the application can read, write, or execute, and symlinks to such files/directories can be listed. To retrieve the permissons for a directory, use the entryInfoList() function to get the associated QFileInfo objects and then use the QFileInfo::permissons() to obtain the permissions and ownership for each file.*//*! Sets the filter used by entryList() and entryInfoList() to \a filters. The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList(). See \l{QDir::Filter}. \sa filter(), setNameFilters()*/void QDir::setFilter(Filters filters){ Q_D(QDir); d->detach(); d->data->filters = filters;}/*! Returns the value set by setSorting() \sa setSorting() SortFlag*/QDir::SortFlags QDir::sorting() const{ Q_D(const QDir); return d->data->sort;}/*! \enum QDir::SortFlag This enum describes the sort options available to QDir, e.g. for entryList() and entryInfoList(). The sort value is specified by OR-ing together values from the following list: \value Name Sort by name. \value Time Sort by time (modification time). \value Size Sort by file size. \value Type Sort by file type (extension). \value Unsorted Do not sort. \value DirsFirst Put the directories first, then the files. \value DirsLast Put the files first, then the directories. \value Reversed Reverse the sort order. \value IgnoreCase Sort case-insensitively. \value LocaleAware Sort items appropriately using the current locale settings. \omitvalue SortByMask \omitvalue DefaultSort \omitvalue NoSort You can only specify one of the first four. If you specify both DirsFirst and Reversed, directories are still put first, but in reverse order; the files will be listed after the directories, again in reverse order.*//*! Sets the sort order used by entryList() and entryInfoList(). The \a sort is specified by OR-ing values from the enum \l{QDir::SortFlag}. \sa sorting() SortFlag*/void QDir::setSorting(SortFlags sort){ Q_D(QDir); d->detach(); d->data->sort = sort;}/*! Returns the total number of directories and files in the directory. Equivalent to entryList().count(). \sa operator[](), entryList()*/uint QDir::count() const{ Q_D(const QDir); d->updateFileLists(); return d->data->files.count();}/*! Returns the file name at position \a pos in the list of file names. Equivalent to entryList().at(index). Returns an empty string if \a pos is out of range or if the entryList() function failed. \sa count(), entryList()*/QString QDir::operator[](int pos) const{ Q_D(const QDir); d->updateFileLists(); return d->data->files[pos];}/*! \overload Returns a list of the names of 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(). The attribute filter and sorting specifications can be overridden using the \a filters and \a sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. \sa entryInfoList(), setNameFilters(), setSorting(), setFilter()*/QStringList QDir::entryList(Filters filters, SortFlags sort) const{ Q_D(const QDir); return entryList(d->data->nameFilters, filters, sort);}/*! \overload 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(). The attribute filter and sorting specifications can be overridden using the \a filters and \a sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()*/QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const{ Q_D(const QDir); return entryInfoList(d->data->nameFilters, filters, sort);}/*! Returns a list of the names of 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(). The name filter, file attribute filter, and sorting specification can be overridden using the \a nameFilters, \a filters, and \a sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. \sa entryInfoList(), setNameFilters(), setSorting(), setFilter()*/QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, SortFlags sort) const{ Q_D(const QDir); if (filters == NoFilter) filters = d->data->filters;#ifdef QT3_SUPPORT if (d->matchAllDirs) filters |= AllDirs;#endif if (sort == NoSort) sort = d->data->sort; if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) { d->updateFileLists(); return d->data->files; } QStringList l = d->data->fileEngine->entryList(filters, nameFilters); QStringList ret; d->sortFileList(sort, l, &ret, 0); return ret;}/*! 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(). The name filter, file attribute filter, and sorting specification can be overridden using the \a nameFilters, \a filters, and \a sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()*/QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters, SortFlags sort) const{ Q_D(const QDir); if (filters == NoFilter) filters = d->data->filters;#ifdef QT3_SUPPORT if (d->matchAllDirs) filters |= AllDirs;#endif if (sort == NoSort) sort = d->data->sort; if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) { d->updateFileLists(); return d->data->fileInfos; } QFileInfoList ret; QStringList l = d->data->fileEngine->entryList(filters, nameFilters); d->sortFileList(sort, l, 0, &ret); return ret;}/*! Creates a sub-directory called \a dirName. Returns true on success; otherwise returns false. \sa rmdir()*/bool QDir::mkdir(const QString &dirName) const{ Q_D(const QDir); if (dirName.isEmpty()) { qWarning("QDir::mkdir: Empty or null file name(s)"); return false; } if(!d->data->fileEngine) return false; QString fn = filePath(dirName); return d->data->fileEngine->mkdir(fn, false);}/*! Removes the directory specified by \a dirName. The directory must be empty for rmdir() to succeed.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -