The path for a directory can also be changed with the cd() and cdUp() functions, both of which operate like familiar shell commands. However, it can also return "." if the QDir represents the current directory. This typically returns the last element in the absolute path that specifies the location of the directory. The name of a directory is found using the dirName() function. The absolute path to a directory is found by calling absolutePath(). Navigation and Directory OperationsĪ directory's path can be obtained with the path() function, and a new path set with the setPath() function. Call makeAbsolute() to convert a relative QDir to an absolute one. You can use the isRelative() or isAbsolute() functions to check if a QDir is using a relative or an absolute file path. On Windows, the second example above will be translated to C:\Documents and Settings when used to access files.Įxamples of relative paths: QDir( "images/landscape.png") Relative file names begin with a directory name or a file name and specify a path relative to the current directory.Įxamples of absolute paths: QDir( "/home/user/Documents") Absolute paths begin with the directory separator (optionally preceded by a drive specification under Windows). If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.Ī QDir can point to a file using either a relative or an absolute path. Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs.
![q-dir search q-dir search](https://support.apple.com/library/content/dam/edam/applecare/images/en_US/itunes/macos-monterey-music-search-itunes-store-callout.png)
It can also be used to access Qt's resource system.
![q-dir search q-dir search](https://4sysops.com/wp-content/uploads/2010/04/WindowsPERescuePStartQDir.png)
The QDir class provides access to directory structures and their contents.Ī QDir is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. SetNameFilters(const QStringList & nameFilters) Rename(const QString & oldName, const QString & newName) RelativeFilePath(const QString & fileName) const QDir(const QString & path, const QString & nameFilter, SortFlags sort = SortFlags( Name | IgnoreCase ), Filters filters = AllEntries)ĪbsoluteFilePath(const QString & fileName) constĮntryInfoList(const QStringList & nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) constĮntryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) constĮntryList(const QStringList & nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) constĮntryList(Filters filters = NoFilter, SortFlags sort = NoSort) const