📄 qdir_win.cpp
字号:
slashify( result ); return result;}/*! 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()*/QString QDir::rootDirPath(){#if defined(Q_FS_FAT) QString d = QString::fromLatin1( getenv("SystemDrive") ); if ( d.isEmpty() ) d = "c:"; d = d + "/";#elif defined(Q_OS_OS2EMX) char dir[4]; _abspath( dir, "/", _MAX_PATH ); QString d( dir );#endif return d;}/*! Returns TRUE if \a path is relative; returns FALSE if it is absolute. \sa isRelative()*/bool QDir::isRelativePath( const QString &path ){ int len = path.length(); if ( len == 0 ) return TRUE; int i = 0; if ( path[0].isLetter() && path[1] == ':' ) // drive, e.g. a: i = 2; return path[i] != '/' && path[i] != '\\';}/*! \internal Reads directory entries.*/bool QDir::readDirEntries( const QString &nameFilter, int filterSpec, int sortSpec ){ int i; QValueList<QRegExp> filters = qt_makeFilterList( nameFilter ); bool doDirs = (filterSpec & Dirs) != 0; bool doFiles = (filterSpec & Files) != 0; bool noSymLinks = (filterSpec & NoSymLinks) != 0; bool doReadable = (filterSpec & Readable) != 0; bool doWritable = (filterSpec & Writable) != 0; bool doExecable = (filterSpec & Executable) != 0; bool doHidden = (filterSpec & Hidden) != 0; // show hidden files if the user asks explicitly for e.g. .* if ( !doHidden && !nameFilter.isEmpty() && nameFilter[0] == '.' ) doHidden = TRUE; bool doModified = (filterSpec & Modified) != 0; bool doSystem = (filterSpec & System) != 0; bool first = TRUE; QString p = dPath.copy(); int plen = p.length(); HANDLE ff; WIN32_FIND_DATA finfo; QFileInfo fi;#undef IS_SUBDIR#undef IS_RDONLY#undef IS_ARCH#undef IS_HIDDEN#undef IS_SYSTEM#undef FF_ERROR#define IS_SUBDIR FILE_ATTRIBUTE_DIRECTORY#define IS_RDONLY FILE_ATTRIBUTE_READONLY#define IS_ARCH FILE_ATTRIBUTE_ARCHIVE#define IS_HIDDEN FILE_ATTRIBUTE_HIDDEN#define IS_SYSTEM FILE_ATTRIBUTE_SYSTEM#define FF_ERROR INVALID_HANDLE_VALUE if ( plen == 0 ) {#if defined(QT_CHECK_NULL) qWarning( "QDir::readDirEntries: No directory name specified" );#endif return FALSE; } if ( p.at(plen-1) != '/' && p.at(plen-1) != '\\' ) p += '/'; p += QString::fromLatin1("*.*"); QT_WA( { ff = FindFirstFile( (TCHAR*)p.ucs2(), &finfo ); }, { // Cast is safe, since char is at end of WIN32_FIND_DATA ff = FindFirstFileA(qt_win95Name(p),(WIN32_FIND_DATAA*)&finfo); } ); if ( !fList ) { fList = new QStringList; Q_CHECK_PTR( fList ); } else { fList->clear(); } if ( ff == FF_ERROR ) { // if it is a floppy disk drive, it might just not have a file on it if ( plen > 1 && p[1] == ':' && ( p[0]=='A' || p[0]=='a' || p[0]=='B' || p[0]=='b' ) ) { if ( !fiList ) { fiList = new QFileInfoList; Q_CHECK_PTR( fiList ); fiList->setAutoDelete( TRUE ); } else { fiList->clear(); } return TRUE; }#if defined(QT_CHECK_RANGE) qWarning( "QDir::readDirEntries: Cannot read the directory: %s (UTF8)", dPath.utf8().data() );#endif return FALSE; } if ( !fiList ) { fiList = new QFileInfoList; Q_CHECK_PTR( fiList ); fiList->setAutoDelete( TRUE ); } else { fiList->clear(); } for ( ;; ) { if ( first ) first = FALSE; else { QT_WA( { if ( !FindNextFile(ff,&finfo) ) break; } , { if ( !FindNextFileA(ff,(WIN32_FIND_DATAA*)&finfo) ) break; } ); } int attrib = finfo.dwFileAttributes; bool isDir = (attrib & IS_SUBDIR) != 0; bool isFile = !isDir; bool isSymLink = FALSE; bool isReadable = TRUE; bool isWritable = (attrib & IS_RDONLY) == 0; bool isExecable = FALSE; bool isModified = (attrib & IS_ARCH) != 0; bool isHidden = (attrib & IS_HIDDEN) != 0; bool isSystem = (attrib & IS_SYSTEM) != 0; QString fname; QT_WA( { fname = QString::fromUcs2( (unsigned short *)finfo.cFileName ); } , { fname = QString::fromLocal8Bit( (const char*)finfo.cFileName ); } ); if ( !qt_matchFilterList(filters, fname) && !(allDirs && isDir) ) continue; if ( (doDirs && isDir) || (doFiles && isFile) ) { QString name = fname; slashify(name); if ( doExecable ) { QString ext = name.right(4).lower(); if ( ext == ".exe" || ext == ".com" || ext == ".bat" || ext == ".pif" || ext == ".cmd" ) isExecable = TRUE; } if ( noSymLinks && isSymLink ) continue; if ( (filterSpec & RWEMask) != 0 ) if ( (doReadable && !isReadable) || (doWritable && !isWritable) || (doExecable && !isExecable) ) continue; if ( doModified && !isModified ) continue; if ( !doHidden && isHidden ) continue; if ( !doSystem && isSystem ) continue; fi.setFile( *this, name ); fiList->append( new QFileInfo( fi ) ); } } FindClose( ff );#undef IS_SUBDIR#undef IS_RDONLY#undef IS_ARCH#undef IS_HIDDEN#undef IS_SYSTEM#undef FF_ERROR // Sort... QDirSortItem* si= new QDirSortItem[fiList->count()]; QFileInfo* itm; i=0; for (itm = fiList->first(); itm; itm = fiList->next()) si[i++].item = itm; qt_cmp_si_sortSpec = sortSpec; qsort( si, i, sizeof(si[0]), qt_cmp_si ); // put them back in the list fiList->setAutoDelete( FALSE ); fiList->clear(); int j; for ( j=0; j<i; j++ ) { fiList->append( si[j].item ); fList->append( si[j].item->fileName() ); } delete [] si; fiList->setAutoDelete( TRUE ); if ( filterSpec == (FilterSpec)filtS && sortSpec == (SortSpec)sortS && nameFilter == nameFilt ) dirty = FALSE; else dirty = TRUE; return TRUE;}/*! 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 (e.g. "/"). The returned pointer is owned by Qt. Callers should \e not delete or modify it.*/const QFileInfoList * QDir::drives(){ // at most one instance of QFileInfoList is leaked, and this variable // points to that list static QFileInfoList * knownMemoryLeak = 0;#ifdef QT_THREAD_SUPPORT QMutexLocker locker( qt_global_mutexpool ? qt_global_mutexpool->get( &knownMemoryLeak ) : 0 );#endif // QT_THREAD_SUPPORT if ( !knownMemoryLeak ) { knownMemoryLeak = new QFileInfoList; knownMemoryLeak->setAutoDelete( TRUE ); } if ( !knownMemoryLeak->count() ) {#if defined(Q_OS_WIN32) Q_UINT32 driveBits = (Q_UINT32) GetLogicalDrives() & 0x3ffffff;#elif defined(Q_OS_OS2EMX) Q_UINT32 driveBits, cur; if (DosQueryCurrentDisk(&cur,&driveBits) != NO_ERROR) exit(1); driveBits &= 0x3ffffff;#endif char driveName[4];#ifndef Q_OS_TEMP qstrcpy( driveName, "A:/" );#else qstrcpy( driveName, "/" );#endif while( driveBits ) { if ( driveBits & 1 ) knownMemoryLeak->append( new QFileInfo( QString::fromLatin1(driveName).upper() ) ); driveName[0]++; driveBits = driveBits >> 1; } } return knownMemoryLeak;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -