⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdir.cpp

📁 doxygen(一个自动从源代码生成文档的工具)的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	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;}/*!  Returns TRUE if the directory exists. (If a file with the same  name is found this function will of course return FALSE).  \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists() const{    QFileInfo fi( dPath );    return fi.exists() && fi.isDir();}/*!  Returns TRUE if the directory path is relative to the current directory,  FALSE if the path is absolute (e.g. under UNIX a path is relative if it  does not start with a '/').  According to Einstein this function should always return TRUE.  \sa convertToAbs()*/bool QDir::isRelative() const{    return isRelativePath( dPath );}/*!  Converts the directory path to an absolute path. If it is already  absolute nothing is done.  \sa isRelative()*/void QDir::convertToAbs(){    dPath = absPath();}/*!  Makes a copy of d and assigns it to this QDir.*/QDir &QDir::operator=( const QDir &d ){    dPath    = d.dPath;    delete fList;    fList    = 0;    delete fiList;    fiList   = 0;    nameFilt = d.nameFilt;    dirty    = TRUE;    allDirs  = d.allDirs;    filtS    = d.filtS;    sortS    = d.sortS;    return *this;}/*!  Sets the directory path to be the given path.*/QDir &QDir::operator=( const QString &path ){    dPath = cleanDirPath( path );    dirty = TRUE;    return *this;}/*!  \fn bool QDir::operator!=( const QDir &d ) const  Returns TRUE if the \e d and this dir have different path or  different sort/filter settings, otherwise FALSE.*//*!  Returns TRUE if the \e d and this dir have the same path and all sort  and filter settings are equal, otherwise FALSE.*/bool QDir::operator==( const QDir &d ) const{    return dPath    == d.dPath &&	   nameFilt == d.nameFilt &&	   allDirs  == d.allDirs &&	   filtS    == d.filtS &&	   sortS    == d.sortS;}/*!  Removes a file.  If \e acceptAbsPath is TRUE a path starting with a separator ('/')  will remove the file with the absolute path, if \e acceptAbsPath is FALSE  any number of separators at the beginning of \e fileName will be removed.  Returns TRUE if successful, otherwise FALSE.*/bool QDir::remove( const QString &fileName, bool acceptAbsPath ){    if ( fileName.isEmpty() ) {#if defined(CHECK_NULL)	qWarning( "QDir::remove: Empty or null file name" );#endif	return FALSE;    }    QString p = filePath( fileName, acceptAbsPath );    return QFile::remove( p );}/*!  Checks for existence of a file.  If \e acceptAbsPaths is TRUE a path starting with a separator ('/')  will check the file with the absolute path, if \e acceptAbsPath is FALSE  any number of separators at the beginning of \e name will be removed.  Returns TRUE if the file exists, otherwise FALSE.  \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists( const QString &name, bool acceptAbsPath ){    if ( name.isEmpty() ) {#if defined(CHECK_NULL)	qWarning( "QDir::exists: Empty or null file name" );#endif	return FALSE;    }    QString tmp = filePath( name, acceptAbsPath );    return QFile::exists( tmp );}/*!  Returns the native directory separator; '/' under UNIX and '\' under  MS-DOS, Windows NT and OS/2.  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.*/char QDir::separator(){#if defined(_OS_UNIX_)    return '/';#elif defined (_OS_FATFS_)    return '\\';#elif defined (_OS_MAC_)    return ':';#else    return '/';#endif}/*!  Returns the current directory.  \sa currentDirPath(), QDir::QDir()*/QDir QDir::current(){    return QDir( currentDirPath() );}/*!  Returns the home directory.  \sa homeDirPath()*/QDir QDir::home(){    return QDir( homeDirPath() );}/*!  Returns the root directory.  \sa rootDirPath() drives()*/QDir QDir::root(){    return QDir( rootDirPath() );}/*!  \fn QString QDir::homeDirPath()  Returns the absolute path for the user's home directory,  \sa home()*/QStringList qt_makeFilterList( const QString &filter ){    if ( filter.isEmpty() )	return QStringList();    QChar sep( ';' );    int i = filter.find( sep, 0 );    if ( i == -1 && filter.find( ' ', 0 ) != -1 )	sep = QChar( ' ' );    QStringList lst = QStringList::split( sep, filter );    QStringList lst2;    QStringList::Iterator it = lst.begin();    for ( ; it != lst.end(); ++it ) {	QString s = *it;	lst2 << s.stripWhiteSpace();    }    return lst2;}/*!  Returns TRUE if the \e fileName matches one of the wildcards in the list \e filters.  \sa QRegExp*/bool QDir::match( const QStringList &filters, const QString &fileName ){    QStringList::ConstIterator sit = filters.begin();    bool matched = FALSE;    for ( ; sit != filters.end(); ++sit ) {	QRegExp regexp( *sit, FALSE, TRUE );	if ( regexp.match( fileName ) != -1 ) {	    matched = TRUE;	    break;	}    }    return matched;}/*!  Returns TRUE if the \e fileName matches the wildcard \e filter.  \a Filter may also contain multiple wildcards separated by spaces or  semicolons.  \sa QRegExp*/bool QDir::match( const QString &filter, const QString &fileName ){    QStringList lst = qt_makeFilterList( filter );    return match( lst, fileName );}/*!  Removes all multiple directory separators ('/') and resolves  any "." or ".." found in the path.  Symbolic links are kept.  This function does not return the  canonical path, but rather the most simplified version of the input.  "../stuff" becomes "stuff", "stuff/../nonsense" becomes "nonsense"  and "\\stuff\\more\\..\\nonsense" becomes "\\stuff\\nonsense".  \sa absPath() canonicalPath()*/QString QDir::cleanDirPath( const QString &filePath ){    QString name = filePath;    QString newPath;    if ( name.isEmpty() )	return name;    slashify( name );    bool addedSeparator;    if ( isRelativePath(name) ) {	addedSeparator = TRUE;	name.insert( 0, '/' );    } else {	addedSeparator = FALSE;    }    int ePos, pos, upLevel;    pos = ePos = name.length();    upLevel = 0;    int len;    while ( pos && (pos = name.findRev('/',--pos)) != -1 ) {	len = ePos - pos - 1;	if ( len == 2 && name.at(pos + 1) == '.'		      && name.at(pos + 2) == '.' ) {	    upLevel++;	} else {	    if ( len != 0 && (len != 1 || name.at(pos + 1) != '.') ) {		if ( !upLevel )		    newPath = QString::fromLatin1("/")			+ name.mid(pos + 1, len) + newPath;		else		    upLevel--;	    }	}	ePos = pos;    }    if ( addedSeparator ) {	while ( upLevel-- )	    newPath.insert( 0, QString::fromLatin1("/..") );	if ( !newPath.isEmpty() )	    newPath.remove( 0, 1 );	else	    newPath = QString::fromLatin1(".");    } else {	if ( newPath.isEmpty() )	    newPath = QString::fromLatin1("/");#if defined(_OS_FATFS_) || defined(_OS_OS2EMX_)	if ( name[0] == '/' ) {	    if ( name[1] == '/' )		// "\\machine\x\ ..."		newPath.insert( 0, '/' );	} else {	    newPath = name.left(2) + newPath;	}#endif    }    return newPath;}int qt_cmp_si_sortSpec;#if defined(Q_C_CALLBACKS)extern "C" {#endifint qt_cmp_si( const void *n1, const void *n2 ){    if ( !n1 || !n2 )	return 0;    QDirSortItem* f1 = (QDirSortItem*)n1;    QDirSortItem* f2 = (QDirSortItem*)n2;    if ( qt_cmp_si_sortSpec & QDir::DirsFirst )	if ( f1->item->isDir() != f2->item->isDir() )	    return f1->item->isDir() ? -1 : 1;    int r = 0;    int sortBy = qt_cmp_si_sortSpec & QDir::SortByMask;    switch ( sortBy ) {      case QDir::Time:	r = f1->item->lastModified().secsTo(f2->item->lastModified());	break;      case QDir::Size:	r = f2->item->size() - f1->item->size();	break;      default:	;    }    if ( r == 0 && sortBy != QDir::Unsorted ) {	// Still not sorted - sort by name	bool ic = qt_cmp_si_sortSpec & QDir::IgnoreCase;	if ( f1->filename_cache.isNull() )	    f1->filename_cache = ic ? f1->item->fileName().lower()				    : f1->item->fileName();	if ( f2->filename_cache.isNull() )	    f2->filename_cache = ic ? f2->item->fileName().lower()				    : f2->item->fileName();	r = f1->filename_cache.compare(f2->filename_cache);    }    if ( r == 0 ) {	// Enforce an order - the order the items appear in the array	r = (char*)n1 - (char*)n2;    }    if ( qt_cmp_si_sortSpec & QDir::Reversed )	return -r;    else	return r;}#if defined(Q_C_CALLBACKS)}#endif#endif // QT_NO_DIR

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -