1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtCore/qstring.h"
33
#include "QtCore/qfileinfo.h"
34
#include "QtCore/qstringlist.h"
38
class Q_CORE_EXPORT QDir
43
Q_DECLARE_PRIVATE(QDir)
45
enum Filter { Dirs = 0x001,
57
PermissionMask = 0x070,
68
CaseSensitive = 0x800,
72
,DefaultFilter = NoFilter
75
Q_DECLARE_FLAGS(Filters, Filter)
77
typedef Filters FilterSpec;
80
enum SortFlag { Name = 0x00,
95
Q_DECLARE_FLAGS(SortFlags, SortFlag)
98
QDir(const QString &path = QString());
99
QDir(const QString &path, const QString &nameFilter,
100
SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = TypeMask);
103
QDir &operator=(const QDir &);
104
QDir &operator=(const QString &path);
106
void setPath(const QString &path);
107
QString path() const;
108
QString absolutePath() const;
109
QString canonicalPath() const;
111
static void addResourceSearchPath(const QString &path);
113
QString dirName() const;
114
QString filePath(const QString &fileName) const;
115
QString absoluteFilePath(const QString &fileName) const;
116
QString relativeFilePath(const QString &fileName) const;
118
static QString convertSeparators(const QString &pathName);
120
bool cd(const QString &dirName);
123
QStringList nameFilters() const;
124
void setNameFilters(const QStringList &nameFilters);
126
Filters filter() const;
127
void setFilter(Filters filter);
128
SortFlags sorting() const;
129
void setSorting(SortFlags sort);
132
QString operator[](int) const;
134
static QStringList nameFiltersFromString(const QString &nameFilter);
136
QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
137
QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
138
SortFlags sort = NoSort) const;
140
QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
141
QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
142
SortFlags sort = NoSort) const;
144
bool mkdir(const QString &dirName) const;
145
bool rmdir(const QString &dirName) const;
146
bool mkpath(const QString &dirPath) const;
147
bool rmpath(const QString &dirPath) const;
149
bool isReadable() const;
153
static bool isRelativePath(const QString &path);
154
inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
155
bool isRelative() const;
156
inline bool isAbsolute() const { return !isRelative(); }
159
bool operator==(const QDir &dir) const;
160
inline bool operator!=(const QDir &dir) const { return !operator==(dir); }
162
bool remove(const QString &fileName);
163
bool rename(const QString &oldName, const QString &newName);
164
bool exists(const QString &name) const;
166
static QFileInfoList drives();
168
static QChar separator();
170
static bool setCurrent(const QString &path);
171
static inline QDir current() { return QDir(currentPath()); }
172
static QString currentPath();
174
static inline QDir home() { return QDir(homePath()); }
175
static QString homePath();
176
static inline QDir root() { return QDir(rootPath()); }
177
static QString rootPath();
178
static inline QDir temp() { return QDir(tempPath()); }
179
static QString tempPath();
182
static bool match(const QStringList &filters, const QString &fileName);
183
static bool match(const QString &filter, const QString &fileName);
185
static QString cleanPath(const QString &path);
186
void refresh() const;
189
typedef SortFlags SortSpec;
190
inline QT3_SUPPORT QString absPath() const { return absolutePath(); }
191
inline QT3_SUPPORT QString absFilePath(const QString &fileName, bool acceptAbsPath = true) const
192
{ Q_UNUSED(acceptAbsPath); return absoluteFilePath(fileName); }
193
inline QT3_SUPPORT bool matchAllDirs() const
194
{ return filter() & AllDirs; }
195
inline QT3_SUPPORT void setMatchAllDirs(bool on)
198
setFilter(filter() | AllDirs);
200
setFilter(filter() & ~(int)AllDirs);
202
inline QT3_SUPPORT QStringList entryList(const QString &nameFilter, Filters filters = NoFilter,
203
SortFlags sort = NoSort) const
204
{ return entryList(nameFiltersFromString(nameFilter), filters, sort); }
205
inline QT3_SUPPORT QFileInfoList entryInfoList(const QString &nameFilter,
206
Filters filters = NoFilter,
207
SortFlags sort = NoSort) const
208
{ return entryInfoList(nameFiltersFromString(nameFilter), filters, sort); }
210
QT3_SUPPORT QString nameFilter() const;
211
QT3_SUPPORT void setNameFilter(const QString &nameFilter);
213
inline QT3_SUPPORT bool mkdir(const QString &dirName, bool acceptAbsPath) const
214
{ Q_UNUSED(acceptAbsPath); return mkdir(dirName); }
215
inline QT3_SUPPORT bool rmdir(const QString &dirName, bool acceptAbsPath) const
216
{ Q_UNUSED(acceptAbsPath); return rmdir(dirName); }
218
inline QT3_SUPPORT void convertToAbs() { makeAbsolute(); }
219
inline QT3_SUPPORT static QString currentDirPath() { return currentPath(); }
220
inline QT3_SUPPORT static QString homeDirPath() { return homePath(); }
221
inline QT3_SUPPORT static QString rootDirPath() { return rootPath(); }
222
inline QT3_SUPPORT static QString cleanDirPath(const QString &name) { return cleanPath(name); }
226
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
227
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)