QDir(3qt)
πΈ NAME πΈ
QDir β access to directory structures and their contents in a platform-independent way. π (Yes bestie, this is QDir from the 3qt manual section. Buckle up.)
β¨ SYNOPSIS β¨
All the functions in this class are reentrant when Qt is built with thread support.
not the stray </p> tag just vibing at the end of that sentence π it's in the original, we respect the original, we move on.
#include <qdir.h>
π Public Members π
enum FilterSpec { Dirs = 0x001, Files = 0x002, Drives = 0x004,
NoSymLinks = 0x008, All = 0x007, TypeMask = 0x00F, Readable = 0x010,
Writable = 0x020, Executable = 0x040, RWEMask = 0x070, Modified =
0x080, Hidden = 0x100, System = 0x200, AccessMask = 0x3F0,
DefaultFilter = -1 }
enum SortSpec { Name = 0x00, Time = 0x01, Size = 0x02, Unsorted = 0x03,
SortByMask = 0x03, DirsFirst = 0x04, Reversed = 0x08, IgnoreCase =
0x10, LocaleAware = 0x20, DefaultSort = -1 }
QDir ()
QDir ( const QString & path, const QString & nameFilter = QString::null,
int sortSpec = Name | IgnoreCase, int filterSpec = All )
QDir ( const QDir & d )
virtual ~QDir ()
QDir & operator= ( const QDir & d )
QDir & operator= ( const QString & path )
virtual void setPath ( const QString & path )
virtual QString path () const
virtual QString absPath () const
virtual QString canonicalPath () const
virtual QString dirName () const
virtual QString filePath ( const QString & fileName, bool acceptAbsPath
= TRUE ) const
virtual QString absFilePath ( const QString & fileName, bool
acceptAbsPath = TRUE ) const
virtual bool cd ( const QString & dirName, bool acceptAbsPath = TRUE )
virtual bool cdUp ()
QString nameFilter () const
virtual void setNameFilter ( const QString & nameFilter )
FilterSpec filter () const
virtual void setFilter ( int filterSpec )
SortSpec sorting () const
virtual void setSorting ( int sortSpec )
bool matchAllDirs () const
virtual void setMatchAllDirs ( bool enable )
uint count () const
QString operator[] ( int index ) const
virtual QStrList encodedEntryList ( int filterSpec = DefaultFilter, int
sortSpec = DefaultSort ) const (obsolete)
virtual QStrList encodedEntryList ( const QString & nameFilter, int
filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const
(obsolete)
virtual QStringList entryList ( int filterSpec = DefaultFilter, int
sortSpec = DefaultSort ) const
virtual QStringList entryList ( const QString & nameFilter, int
filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const
virtual const QFileInfoList * entryInfoList ( int filterSpec =
DefaultFilter, int sortSpec = DefaultSort ) const
virtual const QFileInfoList * entryInfoList ( const QString &
nameFilter, int filterSpec = DefaultFilter, int sortSpec =
DefaultSort ) const
virtual bool mkdir ( const QString & dirName, bool acceptAbsPath = TRUE
) const
virtual bool rmdir ( const QString & dirName, bool acceptAbsPath = TRUE
) const
virtual bool isReadable () const
virtual bool exists () const
virtual bool isRoot () const
virtual bool isRelative () const
virtual void convertToAbs ()
virtual bool operator== ( const QDir & d ) const
virtual bool operator!= ( const QDir & d ) const
virtual bool remove ( const QString & fileName, bool acceptAbsPath =
TRUE )
virtual bool rename ( const QString & oldName, const QString & newName,
bool acceptAbsPaths = TRUE )
virtual bool exists ( const QString & name, bool acceptAbsPath = TRUE )
void refresh () const
π Static Public Members π
QString convertSeparators ( const QString & pathName )
const QFileInfoList * drives ()
char separator ()
bool setCurrent ( const QString & path )
QDir current ()
QDir home ()
QDir root ()
QString currentDirPath ()
QString homeDirPath ()
QString rootDirPath ()
bool match ( const QStringList & filters, const QString & fileName )
bool match ( const QString & filter, const QString & fileName )
QString cleanDirPath ( const QString & filePath )
bool isRelativePath ( const QString & path )
π DESCRIPTION π
The QDir class gives you access to directory structures and their contents in a platform-independent way. That's the whole vibe. π¦
A QDir is what you use to massage path names, pull info about paths and files, and actually go in and mess with the underlying file system. Three jobs, one class, and she does them all. π
A QDir can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator "/" β optionally preceded by a drive specification under Windows. And here's the trick: if you always use "/" as a directory separator, Qt will translate your paths so they conform to whatever the underlying operating system actually wants. Relative file names begin with a directory name or a file name, and they specify a path relative to the current directory.
The "current" path means the application's working directory, periodt. A QDir's own path is set and retrieved with setPath() and path().
So like, an example of an absolute path is the string "/tmp/quartz", and a relative path might look like "src/fatlib". You can use isRelative() to check whether a QDir is riding with a relative or an absolute file path. Call convertToAbs() to convert a relative QDir into an absolute one. Want a simplified path? That's cleanDirPath(). Want a path with no symbolic links and no redundant ".." elements? That's canonicalPath(), and she's iconic for it. The path itself gets set with setPath(), and changed with cd() and cdUp().
QDir also serves up a bunch of static functions, bestie. For example setCurrent() sets the application's working directory, and currentDirPath() retrieves it. Access to some common paths comes from the static functions current(), home() and root(), which hand you back QDir objects β or currentDirPath(), homeDirPath() and rootDirPath(), which hand you the path as a string instead. And if you want to know about your application's path, use QApplication::applicationDirPath().
The number of entries in a directory? That's count(). Want a string list of the names of every file and directory in a directory? entryList(). Prefer a list of QFileInfo pointers? entryInfoList(). Both of those can apply a name filter, an attributes filter (read-only, files-not-directories, etc.), and a sort order. The filters and sort can be set with calls to setNameFilter(), setFilter() and setSorting() β or you can just pass them in the arguments of entryList() and entryInfoList().
Create a new directory with mkdir(), rename a directory with rename(), and remove an existing directory with rmdir(). Remove a file with remove(). And you can interrogate a directory with exists(), isReadable() and isRoot(). Go off. π
To get a path with a filename use filePath(), and to get a directory name use dirName() β heads up though, neither of these functions checks whether the file or directory actually exists. They're just out here doing string math, no cap.
The list of root directories comes from drives(). On Unix systems this returns a list containing one root directory, "/". On Windows the list will usually contain "C:/", and possibly "D:/", etc.
It is easiest to work with "/" separators in Qt code. But if you need to present a path to a user, or need a path in a form suitable for a function in the underlying operating system, use convertSeparators(). π§
π Examples π
Example one: does this directory even exist?
QDir d( "example" ); // "./example"
if ( !d.exists() )
qWarning( "Cannot find the example directory" );
Example two: traversing directories and reading a file.
QDir d = QDir::root(); // "/"
if ( !d.cd("tmp") ) { // "/tmp"
qWarning( "Cannot find the \"/tmp\" directory" );
} else {
QFile f( d.filePath("ex1.txt") ); // "/tmp/ex1.txt"
if ( !f.open(IO_ReadWrite) )
qWarning( "Cannot create the file %s", f.name() );
}
Example three: a program that lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first:
#include <stdio.h>
#include <qdir.h>
int main( int argc, char **argv )
{
QDir d;
d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
d.setSorting( QDir::Size | QDir::Reversed );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
printf( " Bytes Filename\n" );
while ( (fi = it.current()) != 0 ) {
printf( "%10li %s\n", fi->size(), fi->fileName().latin1() );
++it;
}
return 0;
}
See also QApplication::applicationDirPath() and Input/Output and Networking. π«Ά
π Member Type Documentation π
π¦ 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:
QDir::Dirsβ list directories only.QDir::Filesβ list files only.QDir::Drivesβ list disk drives (ignored under Unix).QDir::NoSymLinksβ do not list symbolic links (ignored by operating systems that don't support symbolic links).QDir::Allβ list directories, files, drives and symlinks (this does not list broken symlinks unless you specifySystem).QDir::TypeMaskβ a mask for theDirs,Files,DrivesandNoSymLinksflags.QDir::Readableβ list files for which the application has read access.QDir::Writableβ list files for which the application has write access.QDir::Executableβ list files for which the application has execute access. Executables needs to be combined withDirsorFiles.QDir::RWEMaskβ a mask for theReadable,WritableandExecutableflags.QDir::Modifiedβ only list files that have been modified (ignored under Unix).QDir::Hiddenβ list hidden files (on Unix, files starting with a.).QDir::Systemβ list system files (on Unix, FIFOs, sockets and device files).QDir::AccessMaskβ a mask for theReadable,Writable,Executable,Modified,HiddenandSystemflags.QDir::DefaultFilterβ internal flag.
If you do not set any of Readable, Writable or Executable, QDir will set all three of them. That makes the default easy to write and at the same time useful. π
Examples: application has read access, write access or both. Dirs|Drives means list drives, directories, all files that the application can read, write or execute, and also symlinks to such files/directories.
β¨ QDir::SortSpec β¨
Okay bestie, this enum is literally the glow-up guide for sorting β it tells QDir how to order stuff, like for entryList() and entryInfoList(). You build the sort value by OR-ing together any of these lil gems:
QDir::Nameβ sort by name. iconic.QDir::Timeβ sort by time (modification time).QDir::Sizeβ sort by file size.QDir::Unsortedβ do not sort. chaos, but valid.QDir::SortByMaskβ a mask forName,TimeandSize.QDir::DirsFirstβ put the directories first, then the files.QDir::Reversedβ reverse the sort order.QDir::IgnoreCaseβ sort case-insensitively.QDir::LocaleAwareβ sort names using locale aware comparesQDir::DefaultSortβ internal flag. iykyk.
You can only specify one of the first four. no mixing, periodt.
If you specify both DirsFirst and Reversed, directories are still put first, but in reverse order; the files will be listed after the directories, again in reverse order. the way that works is chef's kiss.
π MEMBER FUNCTION DOCUMENTATION π
QDir::QDir ()
Constructs a QDir pointing to the current directory (".").
See also currentDirPath().
QDir::QDir ( const QString & path, const QString & nameFilter = QString::null, int sortSpec = Name | IgnoreCase, int filterSpec = All )
Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filterSpec. It also sorts the names using sortSpec.
The default nameFilter is an empty string, which excludes nothing; the default filterSpec is All, which also means exclude nothing. The default sortSpec is Name|IgnoreCase, i.e. sort by name case-insensitively. slay.
Example that lists all the files in "/tmp":
QDir d( "/tmp" );
for ( int i = 0; i < d.count(); i++ )
printf( "%s\n", d[i] );
If path is "" or QString::null, QDir uses "." (the current directory). If nameFilter is "" or QString::null, QDir uses the name filter "*" (all files).
Note that path need not exist.
See also exists(), setPath(), setNameFilter(), setFilter(), and setSorting().
QDir::QDir ( const QDir & d )
Constructs a QDir that is a copy of the directory d.
See also operator=().
QDir::~QDir () [virtual]
Destroys the QDir frees up its resources. bye bestie π
QString QDir::absFilePath ( const QString & fileName, bool acceptAbsPath = TRUE ) const [virtual]
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 fileName will not be removed (see cleanDirPath()).
If acceptAbsPath is TRUE a fileName starting with a separator "/" will be returned without change. If acceptAbsPath is FALSE an absolute path will be prepended to the fileName and the resultant string returned.
See also filePath().
QString QDir::absPath () const [virtual]
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
See also setPath(), canonicalPath(), exists(), cleanDirPath(), dirName(), and absFilePath().
Example: fileiconview/qfileiconview.cpp.
QString QDir::canonicalPath () const [virtual]
Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements.
On 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 QString::null.
See also path(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath(), and QString::isNull().
bool QDir::cd ( const QString & dirName, bool acceptAbsPath = TRUE ) [virtual]
Changes the QDir's directory to dirName.
If acceptAbsPath is TRUE a path starting with separator "/" will cause the function to change to the absolute directory. If acceptAbsPath is FALSE any number of separators at the beginning of dirName will be removed and the function will descend into 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. no fake moves, okay?
Calling cd( ".." ) is equivalent to calling cdUp().
See also cdUp(), isReadable(), exists(), and path().
Example: fileiconview/mainwindow.cpp.
bool QDir::cdUp () [virtual]
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.
See also cd(), isReadable(), exists(), and path().
QString QDir::cleanDirPath ( const QString & filePath ) [static]
Removes all multiple directory separators "/" and resolves any"
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".
See also absPath() and canonicalPath().
QString QDir::convertSeparators ( const QString & pathName ) [static]
Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.
On Windows, convertSeparators("c:/winnt/system32") returns" c:\winnt\system32".
The returned string may be the same as the argument on some operating systems, for example on Unix.
Examples:
void QDir::convertToAbs () [virtual]
Converts the directory path to an absolute path. If it is already absolute nothing is done.
See also isRelative().
uint QDir::count () const
Returns the total number of directories and files that were found.
Equivalent to entryList().count().
See also operator[]() and entryList().
QDir QDir::current () [static]
Returns the application's current directory.
Use path() to access a QDir object's path.
See also currentDirPath() and QDir::QDir().
QString QDir::currentDirPath () [static]
Returns the absolute path of the application's current directory.
See also current().
Examples:
QString QDir::dirName () const [virtual]
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. it is the root directory) QString::null is returned.
No check is made to ensure that a directory with this name actually exists.
See also path(), absPath(), absFilePath(), exists(), and QString::isNull().
const QFileInfoList * QDir::drives () [static]
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 not delete or modify it.
Example: dirview/main.cpp.
QStrList QDir::encodedEntryList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const [virtual]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
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 = DefaultFilter, int sortSpec = DefaultSort ) const [virtual]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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().
const QFileInfoList * QDir::entryInfoList ( const QString & nameFilter, int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const [virtual]
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 nameFilter, filterSpec and 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.
Note: QFileInfoList is really a QPtrList<QFileInfo>.
See also entryList(), setNameFilter(), setSorting(), and setFilter().
Examples:
const QFileInfoList * QDir::entryInfoList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const [virtual]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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 filterSpec and 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.
Note: QFileInfoList is really a QPtrList<QFileInfo>.
See also entryList(), setNameFilter(), setSorting(), and setFilter().
QStringList QDir::entryList ( const QString & nameFilter, int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const [virtual]
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 nameFilter, filterSpec and sortSpec arguments.
Returns an empty list if the directory is unreadable or does not exist.
See also entryInfoList(), setNameFilter(), setSorting(), and setFilter().
Example: table/statistics/statistics.cpp.
QStringList QDir::entryList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const [virtual]
okay so this is an overloaded member function, provided for convenience β it behaves essentially like the above function π so don't come for me asking why there's two of them, that's just how Qt rolls.
It 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 filterSpec and sortSpec arguments. π
Returns an empty list if the directory is unreadable or does not exist. π (yeah, empty, not an error, it's giving mysterious.)
See also entryInfoList(), setNameFilter(), setSorting(), and setFilter(). π«Ά
bool QDir::exists ( const QString & name, bool acceptAbsPath = TRUE ) [virtual]
Checks for the existence of the file name. π simple as that bestie.
If acceptAbsPath is TRUE a path starting with separator "/" will check the file with the absolute path. If acceptAbsPath is FALSE any number of separators at the beginning of name will be removed and the resultant file name will be checked. πΈ
Returns TRUE if the file exists; otherwise returns FALSE. periodt.
See also QFileInfo::exists() and QFile::exists(). π
bool QDir::exists () const [virtual]
another overloaded member function, provided for convenience, behaving essentially like the above function. we love a convenient lil overload π
Returns TRUE if the directory exists; otherwise returns FALSE. And listen β if a file with the same name is found this function will return FALSE. not a directory, not my problem, no cap. π
See also QFileInfo::exists() and QFile::exists(). β
QString QDir::filePath ( const QString & fileName, bool acceptAbsPath = TRUE ) const [virtual]
Returns the path name of a file in the directory. π¦ and lowkey it does not check if the file actually exists in the directory β it's just doing path math, not reality checks, okay?
If the QDir is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName will not be removed (see cleanDirPath()). so like, keep that in mind bestie, it's giving "raw string energy". π
If acceptAbsPath is TRUE a fileName starting with a separator "/" will be returned without change. If acceptAbsPath is FALSE an absolute path will be prepended to the fileName and the resultant string returned. β¨
See also absFilePath(), isRelative(), and canonicalPath(). π
FilterSpec QDir::filter () const
Returns the value set by setFilter(). that's it. that's the whole function. iconic minimalism. π
QDir QDir::home () [static]
Returns the home directory. π β¨
Under Windows the HOME environment variable is used. If this does not exist the USERPROFILE environment variable is used. If that does not exist the path is formed by concatenating the HOMEDRIVE and HOMEPATH environment variables. If they don't exist the rootDirPath() is used (this uses the SystemDrive environment variable). If none of these exist C:\ is used. π the fallback chain is literally five layers deep, it's giving "we tried everything".
Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise rootDirPath() is used. πΈ
See also homeDirPath(). π«Ά
QString QDir::homeDirPath () [static]
Returns the absolute path of the user's home directory. the whole path. absolute. no crumbs. π
See also home(). π
bool QDir::isReadable () const [virtual]
Returns TRUE if the directory is readable and we can open files by name; otherwise returns FALSE. π
Warning: AFALSEvalue from this function is not a guarantee that files in the directory are not accessible. okay so like,FALSEdoesn't mean "locked forever", it just means "this check said no". don't be dramatic. π
See also QFileInfo::isReadable(). π
Examples:
bool QDir::isRelative () const [virtual]
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 "/"). π§
See also convertToAbs(). β¨
bool QDir::isRelativePath ( const QString & path ) [static]
Returns TRUE if path is relative; returns FALSE if it is absolute. same vibe check, but static and you hand it the path yourself. π
See also isRelative(). πΈ
bool QDir::isRoot () const [virtual]
Returns TRUE if the directory is the root directory; otherwise returns FALSE. π
Note: If the directory is a symbolic link to the root directory this function returnsFALSE. sneaky!! π If you want to test for this usecanonicalPath(), e.g.
QDir d( "/tmp/root_link" );
d = d.canonicalPath();
if ( d.isRoot() )
qWarning( "It is a root link" );
See also root() and rootDirPath(). π
bool QDir::match ( const QString & filter, const QString & fileName ) [static]
Returns TRUE if the fileName matches the wildcard (glob) pattern filter; otherwise returns FALSE. The filter may contain multiple patterns separated by spaces or semicolons. π
(See QRegExp wildcard matching.) β¨
See also QRegExp::match(). π¦
bool QDir::match ( const QStringList & filters, const QString & fileName ) [static]
yep, another overloaded member function, provided for convenience, behaving essentially like the above function. π
Returns TRUE if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns FALSE. any of them!! it's giving "one of these will hit". π₯
(See QRegExp wildcard matching.) β¨
See also QRegExp::match(). π«Ά
bool QDir::matchAllDirs () const
Returns the value set by setMatchAllDirs(). getter behavior, we love a getter. π
See also setMatchAllDirs(). π
bool QDir::mkdir ( const QString & dirName, bool acceptAbsPath = TRUE ) const [virtual]
Creates a directory. πβ¨ go off, make that folder.
If acceptAbsPath is TRUE a path starting with a separator ('/') will create the absolute directory; if acceptAbsPath is FALSE any number of separators at the beginning of dirName will be removed. πΈ
Returns TRUE if successful; otherwise returns FALSE. π
See also rmdir(). π
QString QDir::nameFilter () const
Returns the string set by setNameFilter(). just hands you the filter back, no notes. π
bool QDir::operator!= ( const QDir & d ) const [virtual]
Returns TRUE if directory d and this directory have different paths or different sort or filter settings; otherwise returns FALSE. it's giving "vibe check failed, you two are not the same". π
Example:
// The current directory is "/usr/local"
QDir d1( "/usr/local/bin" );
QDir d2( "bin" );
if ( d1 != d2 )
qDebug( "They differ" );
QDir & QDir::operator= ( const QDir & d )
Makes a copy of QDir d and assigns it to this QDir. copy paste but make it official. π«Ά
QDir & QDir::operator= ( const QString & path )
overloaded member function, provided for convenience, behaving essentially like the above function. π
Sets the directory path to be the given path. β¨
bool QDir::operator== ( const QDir & d ) const [virtual]
Returns TRUE if directory d and this directory have the same path and their sort and filter settings are the same; otherwise returns FALSE. β¨ soulmate behavior requires matching filters, bestie, no shortcuts.
Example:
// The current directory is "/usr/local"
QDir d1( "/usr/local/bin" );
QDir d2( "bin" );
d2.convertToAbs();
if ( d1 == d2 )
qDebug( "They're the same" );
QString QDir::operator[] ( int index ) const
Returns the file name at position index in the list of file names. Equivalent to entryList().at(index). π―
Returns a QString::null if the index is out of range or if the entryList() function failed. so like, out of bounds gives you a null, not a crash, but still β watch your indexes. π
See also count() and entryList(). π
QString QDir::path () const [virtual]
Returns the path, this may contain symbolic links, but never contains redundant ".", ".." or multiple separators. π§Ή it's giving "tidy but not fully resolved", iykyk.
The returned path can be either absolute or relative (see setPath()). πΈ
See also setPath(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath(), and convertSeparators(). π«Ά
void QDir::refresh () const
Refreshes the directory information. π a lil glow-up for your cached data.
bool QDir::remove ( const QString & fileName, bool acceptAbsPath = TRUE ) [virtual]
Removes the file, fileName. ποΈ bye bestie.
If acceptAbsPath is TRUE a path starting with separator "/" will remove the file with the absolute path. If acceptAbsPath is FALSE any number of separators at the beginning of 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::rename ( const QString & oldName, const QString & newName, bool acceptAbsPaths = TRUE ) [virtual]
Renames a file or directory. β¨ name change era.
If acceptAbsPaths is TRUE a path starting with a separator ('/') will rename the file with the absolute path; if acceptAbsPaths is FALSE any number of separators at the beginning of the names will be removed. πΈ
Returns TRUE if successful; otherwise returns FALSE. π
On most file systems, rename() fails only if oldName does not exist or if newName and oldName are not on the same partition. On Windows, rename() will fail if newName already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if newName points to an open file. π so many ways to fail, it's giving "chaotic". Also note the argument is spelled acceptAbsPaths here with the plural s β do not come for me, that's literally how it is, and do not "fix" it. π
Example: fileiconview/qfileiconview.cpp.
bool QDir::rmdir ( const QString & dirName, bool acceptAbsPath = TRUE ) const [virtual]
Removes a directory. ππ¨
If acceptAbsPath is TRUE a path starting with a separator ('/') will remove the absolute directory; if acceptAbsPath is FALSE any number of separators at the beginning of dirName will be removed. πΈ
The directory must be empty for rmdir() to succeed. empty. like, nothing in it. it will not do the work for you. π«
Returns TRUE if successful; otherwise returns FALSE. π
See also mkdir(). π
QDir QDir::root () [static]
Returns the root directory. π the origin story.
See also rootDirPath() and drives(). π«Ά
QString QDir::rootDirPath () [static]
Returns the absolute path for the root directory. π
For UNIX operating systems this returns "/". For Windows file systems this normally returns "c:/". β¨
See also root() and drives(). π
char QDir::separator () [static]
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. so like, just use the forward slash and let Qt handle it, bestie. π
bool QDir::setCurrent ( const QString & path ) [static]
Sets the application's current working directory to path. Returns TRUE if the directory was successfully changed; otherwise returns FALSE. π§ main character moves the whole app, periodt.
void QDir::setFilter ( int filterSpec ) [virtual]
Sets the filter used by entryList() and entryInfoList() to filterSpec. The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList(). See QDir::FilterSpec. β¨
See also filter() and setNameFilter(). π¦
void QDir::setMatchAllDirs ( bool enable ) [virtual]
If enable is TRUE then all directories are included (e.g. in entryList()), and the nameFilter() is only applied to the files. If enable is FALSE then the nameFilter() is applied to both directories and files. π― pick your fighter.
See also matchAllDirs(). π
void QDir::setNameFilter ( const QString & nameFilter ) [virtual]
Sets the name filter used by entryList() and entryInfoList() to nameFilter. β¨
The nameFilter is a wildcard (globbing) filter that understands "*" and "?" wildcards. (See QRegExp wildcard matching.) 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"). π«Ά
See also nameFilter() and setFilter(). π
void QDir::setPath ( const QString & path ) [virtual]β okay so this one sets the path of the directory topath. That's it, that's the job π . It cleans the path of redundant".",".."and of multiple separators (so it's giving tidy β¨), but no check is made to ensure that a directory with this path actually exists β like, it will absolutely not verify that for you, bestie, it's just vibes and strings.
The path can be either absolute or relative, fr fr. Absolute paths begin with the directory separator "/" (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory. An example of an absolute path is the string "/tmp/quartz", a relative path might look like "src/fatlib". π¦
See also path(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath(), isRelative(), and convertToAbs().
void QDir::setSorting ( int sortSpec ) [virtual]β sets the sort order used byentryList()andentryInfoList(). ThesortSpecis specified by OR-ing values from the enumQDir::SortSpec. π
See also sorting() and SortSpec.
SortSpec QDir::sorting () constβ returns the value set bysetSorting(). Iconic, we love a getter that just gets. π
See also setSorting() and SortSpec.
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
β¨ AUTHOR β¨
Generated automatically from the source code. (Not a human, not a bestie, just a machine doing its little thing π«Ά)
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. (genuinely, thank you, we're obsessed with you for doing this π)
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qdir.3qt) and the Qt version (3.3.8).
ok that's the whole page, bestie!! π this was QDir(3qt) brought to you by Trolltech AS, dated 2 February 2007, living in the Qt 3.3.8 era π mwah, go forth and manipulate directories responsibly β¨πΈ
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms