📄 qdir.3qt
字号:
.br // that are not symbolic links, sorted by size with the smallest files.br // first..br //.br.br int main( int argc, char **argv ).br {.br QDir d;.br d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );.br d.setSorting( QDir::Size | QDir::Reversed );.br.br const QFileInfoList *list = d.entryInfoList();.br QFileInfoListIterator it( *list ); // create list iterator.br QFileInfo *fi; // pointer for traversing.br.br printf( " BYTES FILENAME\\n" ); // print header.br while ( (fi=it.current()) ) { // for each file....br printf( "%10li %s\\n", fi->size(), fi->fileName().data() );.br ++it; // goto next list element.br }.br }.fi.SS "Member Type Documentation".SH "QDir::FilterSpec"This enum describes how QDir is to select what entries in a directory to return. The filter value is specified by or-ing together values from the following list: .TP\fCDirs\fR - List directories only.TP\fCFiles\fR - List files only.TP\fCDrives\fR - List disk drives (does nothing under unix).TP\fCNoSymLinks\fR - Do not list symbolic links (where they exist).TP\fCReadable\fR - List files for which the application has read access..TP\fCWritable\fR - List files for which the application has write access..TP\fCExecutable\fR - List files for which the application has execute access.TP\fCModified\fR - Only list files that have been modified (does nothing under unix).TP\fCHidden\fR - List hidden files (on unix, files starting with a .).TP\fCSystem\fR - List system files (on unix, FIFOs, sockets and device files).PPIf you do not set any of \fCReadable, Writable\fR or \fCExecutable,\fR QDir will set all three of them. This makes the default easy to write and at the same time useful..PPExamples:.)l \fCReadable|Writable\fR means list all files for which theapplication has read access, write access or both. \fCDirs|Drives\fR means list drives, directories, all files that the application can read, write or execute, and also symlinks to such files/directories..SH "QDir::SortSpec"This enum describes how QDir is to sort entries in a directory when it returns a list of them. The sort value is specified by or-ing together values from the following list: .TP\fCName\fR - sort by name.TP\fCTime\fR - sort by time (modification time).TP\fCSize\fR - sort by file size.TP\fCUnsorted\fR - do not sort.TP\fCDirsFirst\fR - put all directories first in the list.TP\fCReversed\fR - reverse the sort order.TP\fCIgnoreCase\fR - sort case-insensitively.IP.PPYou can only specify one of the first four. If you specify both \fCDirsFirst\fR and \fCReversed,\fR directories are still put first but the list is otherwise reversed..SH MEMBER FUNCTION DOCUMENTATION.SH "QDir::QDir ()"Constructs a QDir pointing to the current directory..PPSee also currentDirPath()..SH "QDir::QDir ( const QString & path, const QString & nameFilter = QString::null, int sortSpec = Name | IgnoreCase, int filterSpec = All )"Constructs a QDir..PPArguments:.TP\fIpath\fR is the directory..TP\fInameFilter\fR is the file name filter..TP\fIsortSpec\fR is the sort specification, which describes how to sort the files in the directory..TP\fIfilterSpec\fR is the filter specification, which describes how to filter the files in the directory. Most of these arguments (except \fIpath)\fR have optional values..PPExample:.PP.nf.br // lists all files in /tmp.br.br QDir d( "/tmp" );.br for ( int i=0; i<d.count(); i++ ).br printf( "%s\\n", d[i] );.fi.PPIf \fIpath\fR is "" or null, the directory is set to "." (the current directory). If \fInameFilter\fR is "" or null, it is set to "*" (all files)..PPNo check is made to ensure that the directory exists..PPSee also exists(), setPath(), setNameFilter(), setFilter() and setSorting()..SH "QDir::QDir ( const QDir & d )"Constructs a QDir that is a copy of the given directory..PPSee also operator=()..SH "QDir::~QDir () \fC[virtual]\fR"Destructs the QDir and cleans up..SH "QString QDir::absFilePath ( const QString & fileName, bool acceptAbsPath = TRUE ) const \fC[virtual]\fR"Returns the absolute path name of a file in the directory. Does NOT check if the file actually exists in the directory. Redundant multiple separators or "." and ".." directories in \fIfileName\fR will NOT be removed (see cleanDirPath())..PPIf \fIacceptAbsPath\fR is TRUE a \fIfileName\fR starting with a separator ('/') will be returned without change. if \fIacceptAbsPath\fR is FALSE an absolute path will be appended to the directory path..PPSee also filePath()..SH "QString QDir::absPath () const \fC[virtual]\fR"Returns the absolute (a path that starts with '/') path, which may contain symbolic links, but never contains redundant ".", ".." or multiple separators..PPSee also setPath(), canonicalPath(), exists(), cleanDirPath(), dirName() and absFilePath()..SH "QString QDir::canonicalPath () const \fC[virtual]\fR"Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements..PPOn systems that do not have symbolic links this function will always return the same string that absPath returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath() returns a null string..PPSee also path(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath() and QString::isNull()..SH "bool QDir::cd ( const QString & dirName, bool acceptAbsPath = TRUE ) \fC[virtual]\fR"Changes directory by descending into the given directory. Returns TRUE if the new directory exists and is readable. Note that the logical cd operation is NOT performed if the new directory does not exist..PPIf \fIacceptAbsPath\fR is TRUE a path starting with a separator ('/') will cd to the absolute directory, if \fIacceptAbsPath\fR is FALSE any number of separators at the beginning of \fIdirName\fR will be removed..PPExample:.PP.nf.br QDir d = QDir::home(); // now points to home directory.br if ( !d.cd("c++") ) { // now points to "c++" under home directory if OK.br QFileInfo fi( d, "c++" );.br if ( fi.exists() ) {.br if ( fi.isDir() ).br qWarning( "Cannot cd into \\"%s\\".", (char*)d.absFilePath("c++") );.br else.br qWarning( "Cannot create directory \\"%s\\"\\n".br "A file named \\"c++\\" already exists in \\"%s\\"",.br (const char *)d.absFilePath("c++"),.br (const char *)d.path() );.br return;.br } else {.br qWarning( "Creating directory \\"%s\\"",.br (const char *) d.absFilePath("c++") );.br if ( !d.mkdir( "c++" ) ) {.br qWarning("Could not create directory \\"%s\\"",.br (const char *)d.absFilePath("c++") );.br return;.br }.br }.br }.fi.PPCalling cd( ".." ) is equivalent to calling cdUp()..PPSee also cdUp(), isReadable(), exists() and path()..SH "bool QDir::cdUp () \fC[virtual]\fR"Changes directory by moving one directory up the path followed to arrive at the current directory..PPReturns TRUE if the new directory exists and is readable. Note that the logical cdUp() operation is not performed if the new directory does not exist..PPSee also cd(), isReadable(), exists() and path()..SH "QString QDir::cleanDirPath ( const QString & filePath ) \fC[static]\fR"Removes all multiple directory separators ('/') and resolves any "." or ".." found in the path..PPSymbolic 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"..PPSee also absPath() and canonicalPath()..SH "QString QDir::convertSeparators ( const QString & pathName ) \fC[static]\fR"Converts the '/' separators in \fIpathName\fR to system native separators. Returns the translated string..PPOn Windows, convertSeparators("c:/winnt/system32") returns" c:\\winnt\\system32"..PPNo conversion is done on UNIX..SH "void QDir::convertToAbs () \fC[virtual]\fR"Converts the directory path to an absolute path. If it is already absolute nothing is done..PPSee also isRelative()..SH "uint QDir::count () const"Returns the number of files that was found. Equivalent to entryList().count()..PPSee also operator[]() and entryList()..SH "QDir QDir::current () \fC[static]\fR"Returns the current directory..PPSee also currentDirPath() and QDir::QDir()..SH "QString QDir::currentDirPath () \fC[static]\fR"Returns the absolute path of the current directory..PPSee also current()..SH "QString QDir::dirName () const \fC[virtual]\fR"Returns the name of the directory, this is NOT the same as the path, e.g. a directory with the name "mail", might have the path "/var/spool/mail". If the directory has no name (e.g. the root directory) a null string is returned..PPNo check is made to ensure that a directory with this name actually exists..PPSee also path(), absPath(), absFilePath(), exists() and QString::isNull()..SH "const QFileInfoList * QDir::drives () \fC[static]\fR"Returns a list of the root directories on this system. On win32, 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. "/")..PPThe returned pointer is owned by Qt. Callers should \fInot\fR delete or modify it..SH "QStrList QDir::encodedEntryList ( const QString & nameFilter, int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const \fC[virtual]\fR"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()..PPIt is more efficient to use entryList()..SH "QStrList QDir::encodedEntryList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const \fC[virtual]\fR"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().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -