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

📄 qdir.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
bool QDir::exists() const{    QFileInfo fi( dPath );    return fi.exists() && fi.isDir();}/*!    Returns TRUE if the directory path is relative to the current    directory and returns FALSE if the path is absolute (e.g. under    UNIX a path is relative if it does not start with a "/").    \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 QDir \a 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;}/*!    \overload    Sets the directory path to be the given \a 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 directory \a d and this directory have different    paths or different sort or filter settings; otherwise returns    FALSE.    Example:    \code    // The current directory is "/usr/local"    QDir d1( "/usr/local/bin" );    QDir d2( "bin" );    if ( d1 != d2 )	qDebug( "They differ" );    \endcode*//*!    Returns TRUE if directory \a d and this directory have the same    path and their sort and filter settings are the same; otherwise    returns FALSE.    Example:    \code    // The current directory is "/usr/local"    QDir d1( "/usr/local/bin" );    QDir d2( "bin" );    d2.convertToAbs();    if ( d1 == d2 )	qDebug( "They're the same" );    \endcode*/bool QDir::operator==( const QDir &d ) const{    return dPath    == d.dPath &&	   nameFilt == d.nameFilt &&	   allDirs  == d.allDirs &&	   filtS    == d.filtS &&	   sortS    == d.sortS;}/*!    Removes the file, \a fileName.    If \a acceptAbsPath is TRUE a path starting with separator "/"    will remove the file with the absolute path. If \a acceptAbsPath    is FALSE any number of separators at the beginning of \a fileName    will be removed and the resultant file name will be removed.    Returns TRUE if the file is removed successfully; otherwise    returns FALSE.*/bool QDir::remove( const QString &fileName, bool acceptAbsPath ){    if ( fileName.isEmpty() ) {#if defined(QT_CHECK_NULL)	qWarning( "QDir::remove: Empty or null file name" );#endif	return FALSE;    }    QString p = filePath( fileName, acceptAbsPath );    return QFile::remove( p );}/*!    Checks for the existence of the file \a name.    If \a acceptAbsPath is TRUE a path starting with separator "/"    will check the file with the absolute path. If \a acceptAbsPath is    FALSE any number of separators at the beginning of \a name will be    removed and the resultant file name will be checked.    Returns TRUE if the file exists; otherwise returns FALSE.    \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists( const QString &name, bool acceptAbsPath ) //### const in 4.0{    if ( name.isEmpty() ) {#if defined(QT_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 (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.*/char QDir::separator(){#if defined(Q_OS_UNIX)    return '/';#elif defined (Q_FS_FAT) || defined(Q_WS_WIN)    return '\\';#elif defined (Q_OS_MAC)    return ':';#else    return '/';#endif}/*!    Returns the application's current directory.    Use path() to access a QDir object's path.    \sa currentDirPath(), QDir::QDir()*/QDir QDir::current(){    return QDir( currentDirPath() );}/*!    Returns the 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 rootDirPath() 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 rootDirPath() is used.    \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 of the user's home directory.    \sa home()*/QValueList<QRegExp> qt_makeFilterList( const QString &filter ){    QValueList<QRegExp> regExps;    if ( filter.isEmpty() )	return regExps;    QChar sep( ';' );    int i = filter.find( sep, 0 );    if ( i == -1 && filter.find( ' ', 0 ) != -1 )	sep = QChar( ' ' );    QStringList list = QStringList::split( sep, filter );    QStringList::Iterator it = list.begin();    while ( it != list.end() ) {	regExps << QRegExp( (*it).stripWhiteSpace(), CaseSensitiveFS, TRUE );	++it;    }    return regExps;}bool qt_matchFilterList( const QValueList<QRegExp>& filters,			 const QString &fileName ){    QValueList<QRegExp>::ConstIterator rit = filters.begin();    while ( rit != filters.end() ) {	if ( (*rit).exactMatch(fileName) )	    return TRUE;	++rit;    }    return FALSE;}/*!    \overload    Returns TRUE if the \a fileName matches any of the wildcard (glob)    patterns in the list of \a filters; otherwise returns FALSE.    (See \link qregexp.html#wildcard-matching QRegExp wildcard    matching.\endlink)    \sa QRegExp::match()*/bool QDir::match( const QStringList &filters, const QString &fileName ){    QStringList::ConstIterator sit = filters.begin();    while ( sit != filters.end() ) {	QRegExp rx( *sit, CaseSensitiveFS, TRUE );	if ( rx.exactMatch(fileName) )	    return TRUE;	++sit;    }    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.    (See \link qregexp.html#wildcard-matching QRegExp wildcard    matching.\endlink)    \sa QRegExp::match()*/bool QDir::match( const QString &filter, const QString &fileName ){    return qt_matchFilterList( qt_makeFilterList(filter), fileName );}/*!    Removes all multiple directory separators "/" and resolves any    "."s or ".."s found in the path, \a filePath.    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 absPath() canonicalPath()*/QString QDir::cleanDirPath( const QString &filePath ){    QString name = filePath;    QString newPath;    if ( name.isEmpty() )	return name;    slashify( name );    bool addedSeparator = isRelativePath( name );    if ( addedSeparator )	name.insert( 0, '/' );    int ePos, pos, upLevel;    pos = ePos = name.length();    upLevel = 0;    int len;    while ( pos && (pos = name.findRev('/', pos - 1)) != -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( (uint)0, 1 );	else	    newPath = QString::fromLatin1(".");    } else {	if ( newPath.isEmpty() )	    newPath = QString::fromLatin1("/");#if defined(Q_FS_FAT) || defined(Q_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" {#endif#ifdef Q_OS_TEMPint __cdecl qt_cmp_si( const void *n1, const void *n2 )#elseint qt_cmp_si( const void *n1, const void *n2 )#endif{    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/*! \internal    Detaches all internal data.*/void QDir::detach(){    // deepcopy    dPath = QDeepCopy<QString>(dPath);    nameFilt = QDeepCopy<QString>(nameFilt);    if ( fList )	*fList = QDeepCopy<QStringList>( *fList );    if ( fiList ) {	QFileInfoList *newlist = new QFileInfoList( *fiList );	delete fiList;	fiList = newlist;    }}#endif // QT_NO_DIR

⌨️ 快捷键说明

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