📄 qdir.cpp
字号:
} if(n.contains(':') && n.left(1) != ':') n.prepend(':');#endif return n;}/*! Changes the QDir's directory to \a dirName. If \a acceptAbsPath is TRUE a path starting with separator "/" will cause the function to change to the absolute directory. If \a acceptAbsPath is FALSE any number of separators at the beginning of \a dirName will be removed and the function will descend into \a dirName. Returns TRUE if the new directory exists and is readable; otherwise returns FALSE. Note that the logical cd() operation is not performed if the new directory does not exist. Calling cd( ".." ) is equivalent to calling cdUp(). \sa cdUp(), isReadable(), exists(), path()*/bool QDir::cd( const QString &dirName, bool acceptAbsPath ){ if ( dirName.isEmpty() || dirName == QString::fromLatin1(".") ) return TRUE; QString old = dPath; if ( acceptAbsPath && !isRelativePath(dirName) ) { dPath = cleanDirPath( dirName ); } else { if ( isRoot() ) { if ( dirName == ".." ) { dPath = old; return FALSE; } } else { dPath += '/'; } dPath += dirName; if ( dirName.find('/') >= 0 || old == QString::fromLatin1(".") || dirName == QString::fromLatin1("..") ) { dPath = cleanDirPath( dPath ); /* If dPath starts with .., we convert it to absolute to avoid infinite looping on QDir dir( "." ); while ( dir.cdUp() ) ; */ if ( dPath[0] == QChar('.') && dPath[1] == QChar('.') && (dPath.length() == 2 || dPath[2] == QChar('/')) ) convertToAbs(); } } if ( !exists() ) { dPath = old; // regret return FALSE; } dirty = TRUE; 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("..") );}/*! \fn QString QDir::nameFilter() const Returns the string set by setNameFilter()*//*! Sets the name filter used by entryList() and entryInfoList() to \a nameFilter. The \a nameFilter is a wildcard (globbing) filter that understands "*" and "?" wildcards. (See \link qregexp.html#wildcard-matching QRegExp wildcard matching\endlink.) You may specify several filter entries all separated by a single space " " or by a semi-colon ";". For example, if you want entryList() and entryInfoList() to list all files ending with either ".cpp" or ".h", you would use either dir.setNameFilter("*.cpp *.h") or dir.setNameFilter("*.cpp;*.h"). \sa nameFilter(), setFilter()*/void QDir::setNameFilter( const QString &nameFilter ){ nameFilt = nameFilter; if ( nameFilt.isEmpty() ) nameFilt = QString::fromLatin1("*"); dirty = TRUE;}/*! \fn QDir::FilterSpec QDir::filter() const Returns the value set by setFilter()*//*! \enum QDir::FilterSpec This enum describes the filtering options available to QDir, e.g. for entryList() and entryInfoList(). The filter value is specified by OR-ing together values from the following list: \value Dirs List directories only. \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 All List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System). \value TypeMask A mask for the the Dirs, Files, Drives and NoSymLinks flags. \value Readable List files for which the application has read access. \value Writable List files for which the application has write access. \value Executable List files for which the application has execute access. Executables needs to be combined with Dirs or Files. \value RWEMask A mask for the Readable, Writable and Executable flags. \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 AccessMask A mask for the Readable, Writable, Executable Modified, Hidden and System flags \value DefaultFilter Internal flag. If you do not set any of \c Readable, \c Writable or \c Executable, QDir will set all three of them. This makes the default easy to write and at the same time useful. Examples: \c Readable|Writable means list all files for which the application has read access, write access or both. \c Dirs|Drives means list drives, directories, all files that the application can read, write or execute, and also symlinks to such files/directories.*//*! Sets the filter used by entryList() and entryInfoList() to \a filterSpec. The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList(). See \l{QDir::FilterSpec}. \sa filter(), setNameFilter()*/void QDir::setFilter( int filterSpec ){ if ( filtS == (FilterSpec) filterSpec ) return; filtS = (FilterSpec) filterSpec; dirty = TRUE;}/*! \fn QDir::SortSpec QDir::sorting() const Returns the value set by setSorting() \sa setSorting() SortSpec*//*! \enum QDir::SortSpec 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 Unsorted Do not sort. \value SortByMask A mask for Name, Time and Size. \value DirsFirst Put the directories first, then the files. \value Reversed Reverse the sort order. \value IgnoreCase Sort case-insensitively. \value DefaultSort Internal flag. You can only specify one of the first four. If you specify both \c DirsFirst and \c Reversed, directories are still put first, but in reverse order; the files will be listed after the directories, again in reverse order.*/// ### Unsorted+DirsFirst ? Unsorted+Reversed?/*! Sets the sort order used by entryList() and entryInfoList(). The \a sortSpec is specified by OR-ing values from the enum \l{QDir::SortSpec}. \sa sorting() SortSpec*/void QDir::setSorting( int sortSpec ){ if ( sortS == (SortSpec) sortSpec ) return; sortS = (SortSpec) sortSpec; dirty = TRUE;}/*! \fn bool QDir::matchAllDirs() const Returns the value set by setMatchAllDirs() \sa setMatchAllDirs()*//*! If \a enable is TRUE then all directories are included (e.g. in entryList()), and the nameFilter() is only applied to the files. If \a enable is FALSE then the nameFilter() is applied to both directories and files. \sa matchAllDirs()*/void QDir::setMatchAllDirs( bool enable ){ if ( (bool)allDirs == enable ) return; allDirs = enable; dirty = TRUE;}/*! Returns the total number of directories and files that were found. Equivalent to entryList().count(). \sa operator[](), entryList()*/uint QDir::count() const{ return (uint)entryList().count();}/*! Returns the file name at position \a index in the list of file names. Equivalent to entryList().at(index). Returns a QString::null if the \a index is out of range or if the entryList() function failed. \sa count(), entryList()*/QString QDir::operator[]( int index ) const{ entryList(); return fList && index >= 0 && index < (int)fList->count() ? (*fList)[index] : QString::null;}/*! \obsolete This function is included to easy porting from Qt 1.x to Qt 2.0, it is the same as entryList(), but encodes the filenames as 8-bit strings using QFile::encodedName(). It is more efficient to use entryList().*/QStrList QDir::encodedEntryList( int filterSpec, int sortSpec ) const{ QStrList r; QStringList l = entryList(filterSpec,sortSpec); for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { r.append( QFile::encodeName(*it) ); } return r;}/*! \obsolete \overload This function is included to easy porting from Qt 1.x to Qt 2.0, it is the same as entryList(), but encodes the filenames as 8-bit strings using QFile::encodedName(). It is more efficient to use entryList().*/QStrList QDir::encodedEntryList( const QString &nameFilter, int filterSpec, int sortSpec ) const{ QStrList r; QStringList l = entryList(nameFilter,filterSpec,sortSpec); for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { r.append( QFile::encodeName(*it) ); } return r;}/*! \overload Returns a list of the names of all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter(). The filter and sorting specifications can be overridden using the \a filterSpec and \a sortSpec arguments. Returns an empty list if the directory is unreadable or does not exist. \sa entryInfoList(), setNameFilter(), setSorting(), setFilter()*/QStringList QDir::entryList( int filterSpec, int sortSpec ) const{ if ( !dirty && filterSpec == (int)DefaultFilter && sortSpec == (int)DefaultSort ) return *fList; return entryList( nameFilt, filterSpec, sortSpec );}/*! Returns a list of the names of all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter(). The filter and sorting specifications can be overridden using the \a nameFilter, \a filterSpec and \a sortSpec arguments. Returns an empty list if the directory is unreadable or does not exist. \sa entryInfoList(), setNameFilter(), setSorting(), setFilter()*/QStringList QDir::entryList( const QString &nameFilter, int filterSpec, int sortSpec ) const{ if ( filterSpec == (int)DefaultFilter ) filterSpec = filtS; if ( sortSpec == (int)DefaultSort ) sortSpec = sortS; QDir *that = (QDir*)this; // mutable function if ( that->readDirEntries(nameFilter, filterSpec, sortSpec) ) { if ( that->fList ) return *that->fList; } return QStringList();}/*! \overload Returns a list of QFileInfo objects for all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter(). The filter and sorting specifications can be overridden using the \a filterSpec and \a sortSpec arguments. Returns 0 if the directory is unreadable or does not exist. The returned pointer is a const pointer to a QFileInfoList. The list is owned by the QDir object and will be reused on the next call to entryInfoList() for the same QDir instance. If you want to keep the entries of the list after a subsequent call to this function you must copy them. \sa entryList(), setNameFilter(), setSorting(), setFilter()*/const QFileInfoList *QDir::entryInfoList( int filterSpec, int sortSpec ) const{ if ( !dirty && filterSpec == (int)DefaultFilter && sortSpec == (int)DefaultSort ) return fiList; return entryInfoList( nameFilt, filterSpec, sortSpec );}/*! Returns a list of QFileInfo objects for all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter(). The filter and sorting specifications can be overridden using the \a nameFilter, \a filterSpec and \a sortSpec arguments. Returns 0 if the directory is unreadable or does not exist. The returned pointer is a const pointer to a QFileInfoList. The list is owned by the QDir object and will be reused on the next call to entryInfoList() for the same QDir instance. If you want to keep the entries of the list after a subsequent call to this function you must copy them. \sa entryList(), setNameFilter(), setSorting(), setFilter()*/const QFileInfoList *QDir::entryInfoList( const QString &nameFilter, int filterSpec, int sortSpec ) const{ if ( filterSpec == (int)DefaultFilter ) filterSpec = filtS; if ( sortSpec == (int)DefaultSort ) sortSpec = sortS; QDir *that = (QDir*)this; // mutable function if ( that->readDirEntries(nameFilter, filterSpec, sortSpec) ) return that->fiList; else return 0;}/*! \overload Returns TRUE if the \e directory exists; otherwise returns FALSE. (If a file with the same name is found this function will return FALSE). \sa QFileInfo::exists(), QFile::exists()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -