Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
QDir Class Reference

Traverses directory structures and contents in a platform-independent way. More...

#include <qdir.h>

Public Types

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,
  DefaultSort = -1
}
 

Public Member Functions

 QDir ()
 
 QDir (const QString &path, const QString &nameFilter=QString::null, int sortSpec=Name|IgnoreCase, int filterSpec=All)
 
 QDir (const QDir &)
 
virtual ~QDir ()
 
QDiroperator= (const QDir &)
 
QDiroperator= (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)
 
uint count () const
 
QString operator[] (int) const
 
virtual QStrList encodedEntryList (int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
 
virtual QStrList encodedEntryList (const QString &nameFilter, int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
 
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 QFileInfoListentryInfoList (int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
 
virtual const QFileInfoListentryInfoList (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 &) const
 
virtual bool operator!= (const QDir &) const
 
virtual bool remove (const QString &fileName, bool acceptAbsPath=TRUE)
 
virtual bool rename (const QString &name, const QString &newName, bool acceptAbsPaths=TRUE)
 
virtual bool exists (const QString &name, bool acceptAbsPath=TRUE)
 

Static Public Member Functions

static QString convertSeparators (const QString &pathName)
 
static const QFileInfoListdrives ()
 
static char separator ()
 
static bool setCurrent (const QString &path)
 
static QDir current ()
 
static QDir home ()
 
static QDir root ()
 
static QString currentDirPath ()
 
static QString homeDirPath ()
 
static QString rootDirPath ()
 
static bool match (const QStringList &filters, const QString &fileName)
 
static bool match (const QString &filter, const QString &fileName)
 
static QString cleanDirPath (const QString &dirPath)
 
static bool isRelativePath (const QString &path)
 

Private Member Functions

void init ()
 
virtual bool readDirEntries (const QString &nameFilter, int FilterSpec, int SortSpec)
 

Static Private Member Functions

static void slashify (QString &)
 

Private Attributes

QString dPath
 
QStringListfList
 
QFileInfoListfiList
 
QString nameFilt
 
FilterSpec filtS
 
SortSpec sortS
 
uint dirty: 1
 
uint allDirs: 1
 

Detailed Description

Traverses directory structures and contents in a platform-independent way.

A QDir can point to a file using either a relative or an absolute file path. Absolute file paths begin with the directory separator ('/') or a drive specification (not applicable to UNIX). 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". You can use the function isRelative() to check if a QDir is using a relative or an absolute file path. You can call the function convertToAbs() to convert a relative QDir to an absolute one.

The directory "example" under the current directory is checked for existence in the example below:

QDir d( "example" ); // "./example"
if ( !d.exists() )
qWarning( "Cannot find the example directory" );

If you always use '/' as a directory separator, Qt will translate your paths to conform to the underlying operating system.

cd() and cdUp() can be used to navigate the directory tree. Note that the logical cd and cdUp operations are not performed if the new directory does not exist.

Example:

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() );
}

To read the contents of a directory you can use the entryList() and entryInfoList() functions.

Example:

#include <stdio.h>
#include <qdir.h>
//
// This program scans the current directory and lists all files
// that are not symbolic links, sorted by size with the smallest files
// first.
//
int main( int argc, char **argv )
{
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list ); // create list iterator
QFileInfo *fi; // pointer for traversing
printf( " BYTES FILENAME\n" ); // print header
while ( (fi=it.current()) ) { // for each file...
printf( "%10li %s\n", fi->size(), fi->fileName().data() );
++it; // goto next list element
}
}

Definition at line 52 of file qdir.h.

Member Enumeration Documentation

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:

  • Dirs - List directories only
  • Files - List files only

  • Drives - List disk drives (does nothing under unix)
  • NoSymLinks - Do not list symbolic links (where they exist)
  • Readable - List files for which the application has read access.
  • Writable - List files for which the application has write access.
  • Executable - List files for which the application has execute access
  • Modified - Only list files that have been modified (does nothing under unix)
  • Hidden - List hidden files (on unix, files starting with a .)
  • System - List system files (does nothing under unix)

If you do not set any of Readable, Writable or Executable, QDir will set all three of them. This makes the default easy to write and at the same time useful.

Examples: Readable|Writable means list all files for which the 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.

Enumerator
Dirs 
Files 
Drives 
NoSymLinks 
All 
TypeMask 
Readable 
Writable 
Executable 
RWEMask 
Modified 
Hidden 
System 
AccessMask 
DefaultFilter 

Definition at line 55 of file qdir.h.

55  { Dirs = 0x001,
56  Files = 0x002,
57  Drives = 0x004,
58  NoSymLinks = 0x008,
59  All = 0x007,
60  TypeMask = 0x00F,
61 
62  Readable = 0x010,
63  Writable = 0x020,
64  Executable = 0x040,
65  RWEMask = 0x070,
66 
67  Modified = 0x080,
68  Hidden = 0x100,
69  System = 0x200,
70  AccessMask = 0x3F0,
71 
72  DefaultFilter = -1 };
Definition: qdir.h:59

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:

  • Name - sort by name
  • Time - sort by time (modification time)
  • Size - sort by file size
  • Unsorted - do not sort

  • DirsFirst - put all directories first in the list
  • Reversed - reverse the sort order
  • IgnoreCase - sort case-insensitively

You can only specify one of the first four. If you specify both DirsFirst and Reversed, directories are still put first but the list is otherwise reversed.

Enumerator
Name 
Time 
Size 
Unsorted 
SortByMask 
DirsFirst 
Reversed 
IgnoreCase 
DefaultSort 

Definition at line 74 of file qdir.h.

74  { Name = 0x00,
75  Time = 0x01,
76  Size = 0x02,
77  Unsorted = 0x03,
78  SortByMask = 0x03,
79 
80  DirsFirst = 0x04,
81  Reversed = 0x08,
82  IgnoreCase = 0x10,
83  DefaultSort = -1 };
ChannelGroupService::Name Name

Constructor & Destructor Documentation

QDir::QDir ( )

Constructs a QDir pointing to the current directory.

See also
currentDirPath()

Definition at line 137 of file qdir.cpp.

138 {
139  dPath = QString::fromLatin1(".");
140  init();
141 }
void init()
Definition: qdir.cpp:205
QString dPath
Definition: qdir.h:187
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
QDir::QDir ( const QString path,
const QString nameFilter = QString::null,
int  sortSpec = Name | IgnoreCase,
int  filterSpec = All 
)

Constructs a QDir.

  • path is the directory.
  • nameFilter is the file name filter.
  • sortSpec is the sort specification, which describes how to sort the files in the directory.
  • filterSpec is the filter specification, which describes how to filter the files in the directory.

Most of these arguments (except path) have optional values.

Example:

// lists all files in /tmp
QDir d( "/tmp" );
for ( int i=0; i<d.count(); i++ )
printf( "%s\n", d[i] );

If path is "" or null, the directory is set to "." (the current directory). If nameFilter is "" or null, it is set to "*" (all files).

No check is made to ensure that the directory exists.

See also
exists(), setPath(), setNameFilter(), setFilter(), setSorting()

Definition at line 173 of file qdir.cpp.

175 {
176  init();
177  dPath = cleanDirPath( path );
178  if ( dPath.isEmpty() )
179  dPath = QString::fromLatin1(".");
181  if ( nameFilt.isEmpty() )
183  filtS = (FilterSpec)filterSpec;
184  sortS = (SortSpec)sortSpec;
185 }
QString nameFilt
Definition: qdir.h:190
static QString cleanDirPath(const QString &dirPath)
Definition: qdir.cpp:1077
QString nameFilter() const
Definition: qdir.h:203
bool isEmpty() const
Definition: qstring.h:682
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
SortSpec
Definition: qdir.h:74
void init()
Definition: qdir.cpp:205
QString dPath
Definition: qdir.h:187
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
FilterSpec
Definition: qdir.h:55
QDir::QDir ( const QDir d)

Constructs a QDir that is a copy of the given directory.

See also
operator=()

Definition at line 192 of file qdir.cpp.

193 {
194  dPath = d.dPath;
195  fList = 0;
196  fiList = 0;
197  nameFilt = d.nameFilt;
198  dirty = TRUE;
199  allDirs = d.allDirs;
200  filtS = d.filtS;
201  sortS = d.sortS;
202 }
QString nameFilt
Definition: qdir.h:190
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
QString dPath
Definition: qdir.h:187
QStringList * fList
Definition: qdir.h:188
uint allDirs
Definition: qdir.h:194
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
QFileInfoList * fiList
Definition: qdir.h:189
QDir::~QDir ( )
virtual

Destructs the QDir and cleans up.

Definition at line 220 of file qdir.cpp.

221 {
222  if ( fList )
223  delete fList;
224  if ( fiList )
225  delete fiList;
226 }
QStringList * fList
Definition: qdir.h:188
QFileInfoList * fiList
Definition: qdir.h:189

Member Function Documentation

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 appended to the directory path.

See also
filePath()

Definition at line 351 of file qdir.cpp.

353 {
354  if ( acceptAbsPath && !isRelativePath( fileName ) )
355  return fileName;
356 
357  QString tmp = absPath();
358  if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName &&
359  fileName[0] != '/') )
360  tmp += '/';
361  tmp += fileName;
362  return tmp;
363 }
bool isEmpty() const
Definition: qstring.h:682
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
virtual QString absPath() const
Definition: qdir.cpp:276
fileName
Definition: dumpTree.py:9
uint length() const
Definition: qstring.h:679
string tmp
Definition: languages.py:63
QString QDir::absPath ( ) const
virtual

Returns the absolute (a path that starts with '/') path, which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.

See also
setPath(), canonicalPath(), exists(), cleanDirPath(), dirName(), absFilePath()

Definition at line 276 of file qdir.cpp.

277 {
278  if ( QDir::isRelativePath(dPath) ) {
280  if ( tmp.right(1) != QString::fromLatin1("/") )
281  tmp += '/';
282  tmp += dPath;
283  return cleanDirPath( tmp );
284  } else {
285  return cleanDirPath( dPath );
286  }
287 }
static QString cleanDirPath(const QString &dirPath)
Definition: qdir.cpp:1077
QString dPath
Definition: qdir.h:187
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
static QString currentDirPath()
Definition: qdir_unix.cpp:141
string tmp
Definition: languages.py:63
QString right(uint len) const
Definition: qstring.cpp:13231
QString QDir::canonicalPath ( ) const
virtual

Definition at line 79 of file qdir_unix.cpp.

80 {
81  QString r;
82 
83  char cur[PATH_MAX];
84  char tmp[PATH_MAX];
85  if (GETCWD( cur, PATH_MAX )) {
86  if ( CHDIR(QFile::encodeName(dPath)) >= 0 ) {
87  if (GETCWD( tmp, PATH_MAX )) {
88  r = QFile::decodeName(tmp);
89  }
90  (void)CHDIR( cur );
91  }
92  }
93 
94  slashify( r );
95  return r;
96 }
static void slashify(QString &)
Definition: qdir_unix.cpp:65
#define CHDIR
Definition: qfiledefs_p.h:222
#define PATH_MAX
Definition: qfiledefs_p.h:92
QString dPath
Definition: qdir.h:187
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
#define GETCWD
Definition: qfiledefs_p.h:221
string tmp
Definition: languages.py:63
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
bool QDir::cd ( const QString dirName,
bool  acceptAbsPath = TRUE 
)
virtual

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.

If acceptAbsPath is TRUE a path starting with a separator ('/') will cd to the absolute directory, if acceptAbsPath is FALSE any number of separators at the beginning of dirName will be removed.

Example:

QDir d = QDir::home(); // now points to home directory
if ( !d.cd("c++") ) { // now points to "c++" under home directory if OK
QFileInfo fi( d, "c++" );
if ( fi.exists() ) {
if ( fi.isDir() )
qWarning( "Cannot cd into \"%s\".", (char*)d.absFilePath("c++") );
else
qWarning( "Cannot create directory \"%s\"\n"
"A file named \"c++\" already exists in \"%s\"",
(const char *)d.absFilePath("c++"),
(const char *)d.path() );
return;
} else {
qWarning( "Creating directory \"%s\"",
(const char *) d.absFilePath("c++") );
if ( !d.mkdir( "c++" ) ) {
qWarning("Could not create directory \"%s\"",
(const char *)d.absFilePath("c++") );
return;
}
}
}

Calling cd( ".." ) is equivalent to calling cdUp().

See also
cdUp(), isReadable(), exists(), path()

Definition at line 429 of file qdir.cpp.

430 {
431  if ( dirName.isEmpty() || dirName==QString::fromLatin1(".") )
432  return TRUE;
433  QString old = dPath;
434  if ( acceptAbsPath && !isRelativePath(dirName) ) {
435  dPath = cleanDirPath( dirName );
436  } else {
437  if ( !isRoot() )
438  dPath += '/';
439  dPath += dirName;
440  if ( dirName.find('/') >= 0
441  || old == QString::fromLatin1(".")
442  || dirName == QString::fromLatin1("..") )
443  dPath = cleanDirPath( dPath );
444  }
445  if ( !exists() ) {
446  dPath = old; // regret
447  return FALSE;
448  }
449  dirty = TRUE;
450  return TRUE;
451 }
static QString cleanDirPath(const QString &dirPath)
Definition: qdir.cpp:1077
bool isEmpty() const
Definition: qstring.h:682
virtual QString dirName() const
Definition: qdir.cpp:300
const bool FALSE
Definition: qglobal.h:370
QString dPath
Definition: qdir.h:187
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
virtual bool isRoot() const
Definition: qdir_unix.cpp:114
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
uint dirty
Definition: qdir.h:193
virtual bool exists() const
Definition: qdir.cpp:820
const bool TRUE
Definition: qglobal.h:371
bool QDir::cdUp ( )
virtual

Changes directory by moving one directory up the path followed to arrive at the current directory.

Returns 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.

See also
cd(), isReadable(), exists(), path()

Definition at line 464 of file qdir.cpp.

465 {
466  return cd( QString::fromLatin1("..") );
467 }
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
virtual bool cd(const QString &dirName, bool acceptAbsPath=TRUE)
Definition: qdir.cpp:429
QString QDir::cleanDirPath ( const QString filePath)
static

Removes all multiple directory separators ('/') and resolves any "." or ".." found in the path.

Symbolic 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".

See also
absPath() canonicalPath()

Definition at line 1077 of file qdir.cpp.

1078 {
1079  QString name = filePath;
1080  QString newPath;
1081 
1082  if ( name.isEmpty() )
1083  return name;
1084 
1085  slashify( name );
1086 
1087  bool addedSeparator;
1088  if ( isRelativePath(name) ) {
1089  addedSeparator = TRUE;
1090  name.insert( 0, '/' );
1091  } else {
1092  addedSeparator = FALSE;
1093  }
1094 
1095  int ePos, pos, upLevel;
1096 
1097  pos = ePos = name.length();
1098  upLevel = 0;
1099  int len;
1100 
1101  while ( pos && (pos = name.findRev('/',--pos)) != -1 ) {
1102  len = ePos - pos - 1;
1103  if ( len == 2 && name.at(pos + 1) == '.'
1104  && name.at(pos + 2) == '.' ) {
1105  upLevel++;
1106  } else {
1107  if ( len != 0 && (len != 1 || name.at(pos + 1) != '.') ) {
1108  if ( !upLevel )
1109  newPath = QString::fromLatin1("/")
1110  + name.mid(pos + 1, len) + newPath;
1111  else
1112  upLevel--;
1113  }
1114  }
1115  ePos = pos;
1116  }
1117  if ( addedSeparator ) {
1118  while ( upLevel-- )
1119  newPath.insert( 0, QString::fromLatin1("/..") );
1120  if ( !newPath.isEmpty() )
1121  newPath.remove( 0, 1 );
1122  else
1123  newPath = QString::fromLatin1(".");
1124  } else {
1125  if ( newPath.isEmpty() )
1126  newPath = QString::fromLatin1("/");
1127 #if defined(_OS_FATFS_) || defined(_OS_OS2EMX_)
1128  if ( name[0] == '/' ) {
1129  if ( name[1] == '/' ) // "\\machine\x\ ..."
1130  newPath.insert( 0, '/' );
1131  } else {
1132  newPath = name.left(2) + newPath;
1133  }
1134 #endif
1135  }
1136  return newPath;
1137 }
static QCString name
Definition: declinfo.cpp:673
static void slashify(QString &)
Definition: qdir_unix.cpp:65
bool isEmpty() const
Definition: qstring.h:682
QString mid(uint index, uint len=0xffffffff) const
Definition: qstring.cpp:13265
const bool FALSE
Definition: qglobal.h:370
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
QString & remove(uint index, uint len)
Definition: qstring.cpp:13633
QChar at(uint i) const
Definition: qstring.h:492
QString left(uint len) const
Definition: qstring.cpp:13199
uint length() const
Definition: qstring.h:679
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
QString & insert(uint index, const QString &)
Definition: qstring.cpp:13523
const bool TRUE
Definition: qglobal.h:371
QString QDir::convertSeparators ( const QString pathName)
static

Converts the '/' separators in pathName to system native separators. Returns the translated string.

On Windows, convertSeparators("c:/winnt/system32") returns "c:\winnt\system32".

No conversion is done on UNIX.

Definition at line 376 of file qdir.cpp.

377 {
378  QString n( pathName );
379 #if defined(_OS_FATFS_) || defined(_OS_OS2EMX_)
380  for ( int i=0; i<(int)n.length(); i++ ) {
381  if ( n[i] == '/' )
382  n[i] = '\\';
383  }
384 #endif
385  return n;
386 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
std::void_t< T > n
void QDir::convertToAbs ( )
virtual

Converts the directory path to an absolute path. If it is already absolute nothing is done.

See also
isRelative()

Definition at line 848 of file qdir.cpp.

849 {
850  dPath = absPath();
851 }
QString dPath
Definition: qdir.h:187
virtual QString absPath() const
Definition: qdir.cpp:276
uint QDir::count ( ) const

Returns the number of files that was found. Equivalent to entryList().count().

See also
operator[](), entryList()

Definition at line 641 of file qdir.cpp.

642 {
643  return entryList().count();
644 }
uint count() const
Definition: qvaluelist.h:394
virtual QStringList entryList(int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
Definition: qdir.cpp:717
QDir QDir::current ( )
static

Returns the current directory.

See also
currentDirPath(), QDir::QDir()

Definition at line 978 of file qdir.cpp.

979 {
980  return QDir( currentDirPath() );
981 }
QDir()
Definition: qdir.cpp:137
static QString currentDirPath()
Definition: qdir_unix.cpp:141
QString QDir::currentDirPath ( )
static

Definition at line 141 of file qdir_unix.cpp.

142 {
143  QString result;
144 
145  STATBUF st;
146  if ( STAT( ".", &st ) == 0 ) {
147  char currentName[PATH_MAX];
148  if ( GETCWD( currentName, PATH_MAX ) != 0 )
149  result = QFile::decodeName(currentName);
150 #if defined(DEBUG)
151  if ( result.isNull() )
152  qWarning( "QDir::currentDirPath: getcwd() failed" );
153 #endif
154  } else {
155 #if defined(DEBUG)
156  qWarning( "QDir::currentDirPath: stat(\".\") failed" );
157 #endif
158  }
159  slashify( result );
160  return result;
161 }
static void slashify(QString &)
Definition: qdir_unix.cpp:65
#define STATBUF
Definition: qfiledefs_p.h:199
static QCString result
#define PATH_MAX
Definition: qfiledefs_p.h:92
#define STAT
Definition: qfiledefs_p.h:201
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
#define GETCWD
Definition: qfiledefs_p.h:221
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
bool isNull() const
Definition: qstring.h:379
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. the root directory) a null string is returned.

No check is made to ensure that a directory with this name actually exists.

See also
path(), absPath(), absFilePath(), exists(), QString::isNull()

Definition at line 300 of file qdir.cpp.

301 {
302  int pos = dPath.findRev( '/' );
303  if ( pos == -1 )
304  return dPath;
305  return dPath.right( dPath.length() - pos - 1 );
306 }
QString dPath
Definition: qdir.h:187
uint length() const
Definition: qstring.h:679
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
QString right(uint len) const
Definition: qstring.cpp:13231
const QFileInfoList * QDir::drives ( )
static

Definition at line 276 of file qdir_unix.cpp.

277 {
278  // at most one instance of QFileInfoList is leaked, and this variable
279  // points to that list
280  static QFileInfoList * knownMemoryLeak = 0;
281 
282  if ( !knownMemoryLeak ) {
283  knownMemoryLeak = new QFileInfoList;
284  // non-win32 versions both use just one root directory
285  knownMemoryLeak->append( new QFileInfo( rootDirPath() ) );
286  }
287 
288  return knownMemoryLeak;
289 }
QInternalList< QFileInfo > QFileInfoList
Definition: qdir.h:47
static QString rootDirPath()
Definition: qdir_unix.cpp:163
void append(const type *d)
Definition: qinternallist.h:61
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
QStrList QDir::encodedEntryList ( int  filterSpec = DefaultFilter,
int  sortSpec = DefaultSort 
) const
virtual

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().

Definition at line 672 of file qdir.cpp.

673 {
674  QStrList r;
675  QStringList l = entryList(filterSpec,sortSpec);
676  for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
677  r.append( QFile::encodeName(*it) );
678  }
679  return r;
680 }
Iterator end()
Definition: qvaluelist.h:363
static QStrList * l
Definition: config.cpp:1044
A list of strings.
Definition: qstringlist.h:51
void append(const type *d)
Definition: qinternallist.h:61
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
Iterator begin()
Definition: qvaluelist.h:361
virtual QStringList entryList(int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
Definition: qdir.cpp:717
QStrList QDir::encodedEntryList ( const QString nameFilter,
int  filterSpec = DefaultFilter,
int  sortSpec = DefaultSort 
) const
virtual

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().

Definition at line 689 of file qdir.cpp.

692 {
693  QStrList r;
694  QStringList l = entryList(nameFilter,filterSpec,sortSpec);
695  for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
696  r.append( QFile::encodeName(*it) );
697  }
698  return r;
699 }
Iterator end()
Definition: qvaluelist.h:363
static QStrList * l
Definition: config.cpp:1044
A list of strings.
Definition: qstringlist.h:51
void append(const type *d)
Definition: qinternallist.h:61
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
Iterator begin()
Definition: qvaluelist.h:361
virtual QStringList entryList(int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
Definition: qdir.cpp:717
const QFileInfoList * QDir::entryInfoList ( int  filterSpec = DefaultFilter,
int  sortSpec = DefaultSort 
) const
virtual

Returns a list of QFileInfo objects for all files and directories in the directory pointed to using the setSorting(), setFilter() and setNameFilter() specifications.

The 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 will need to copy them.

See also
entryList(), setNameFilter(), setSorting(), setFilter()

Definition at line 772 of file qdir.cpp.

773 {
774  if ( !dirty && filterSpec == (int)DefaultFilter &&
775  sortSpec == (int)DefaultSort )
776  return fiList;
777  return entryInfoList( nameFilt, filterSpec, sortSpec );
778 }
QString nameFilt
Definition: qdir.h:190
virtual const QFileInfoList * entryInfoList(int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
Definition: qdir.cpp:772
uint dirty
Definition: qdir.h:193
QFileInfoList * fiList
Definition: qdir.h:189
const QFileInfoList * QDir::entryInfoList ( const QString nameFilter,
int  filterSpec = DefaultFilter,
int  sortSpec = DefaultSort 
) const
virtual

Returns a list of QFileInfo objects for all files and directories in the directory pointed to using the setSorting(), setFilter() and setNameFilter() specifications.

The 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 will need to copy them.

See also
entryList(), setNameFilter(), setSorting(), setFilter()

Definition at line 799 of file qdir.cpp.

801 {
802  if ( filterSpec == (int)DefaultFilter )
803  filterSpec = filtS;
804  if ( sortSpec == (int)DefaultSort )
805  sortSpec = sortS;
806  QDir *that = (QDir*)this; // mutable function
807  if ( that->readDirEntries(nameFilter, filterSpec, sortSpec) )
808  return that->fiList;
809  else
810  return 0;
811 }
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
virtual bool readDirEntries(const QString &nameFilter, int FilterSpec, int SortSpec)
Definition: qdir_unix.cpp:177
QFileInfoList * fiList
Definition: qdir.h:189
QStringList QDir::entryList ( int  filterSpec = DefaultFilter,
int  sortSpec = DefaultSort 
) const
virtual

Returns a list of the names of all files and directories in the directory indicated by the setSorting(), setFilter() and setNameFilter() specifications.

The 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.

See also
entryInfoList(), setNameFilter(), setSorting(), setFilter(), encodedEntryList()

Definition at line 717 of file qdir.cpp.

718 {
719  if ( !dirty && filterSpec == (int)DefaultFilter &&
720  sortSpec == (int)DefaultSort )
721  return *fList;
722  return entryList( nameFilt, filterSpec, sortSpec );
723 }
QString nameFilt
Definition: qdir.h:190
QStringList * fList
Definition: qdir.h:188
uint dirty
Definition: qdir.h:193
virtual QStringList entryList(int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
Definition: qdir.cpp:717
QStringList QDir::entryList ( const QString nameFilter,
int  filterSpec = DefaultFilter,
int  sortSpec = DefaultSort 
) const
virtual

Returns a list of the names of all files and directories in the directory indicated by the setSorting(), setFilter() and setNameFilter() specifications.

The the filter and sorting specifications can be overridden using the nameFilter, filterSpec and sortSpec arguments.

Returns and empty list if the directory is unreadable or does not exist.

See also
entryInfoList(), setNameFilter(), setSorting(), setFilter(), encodedEntryList()

Definition at line 739 of file qdir.cpp.

741 {
742  if ( filterSpec == (int)DefaultFilter )
743  filterSpec = filtS;
744  if ( sortSpec == (int)DefaultSort )
745  sortSpec = sortS;
746  QDir *that = (QDir*)this; // mutable function
747  if ( that->readDirEntries(nameFilter, filterSpec, sortSpec) )
748  return *that->fList;
749  else
750  return QStringList();
751 }
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
A list of strings.
Definition: qstringlist.h:51
virtual bool readDirEntries(const QString &nameFilter, int FilterSpec, int SortSpec)
Definition: qdir_unix.cpp:177
QStringList * fList
Definition: qdir.h:188
bool QDir::exists ( ) const
virtual

Returns TRUE if the directory exists. (If a file with the same name is found this function will of course return FALSE).

See also
QFileInfo::exists(), QFile::exists()

Definition at line 820 of file qdir.cpp.

821 {
822  QFileInfo fi( dPath );
823  return fi.exists() && fi.isDir();
824 }
QString dPath
Definition: qdir.h:187
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
bool QDir::exists ( const QString name,
bool  acceptAbsPath = TRUE 
)
virtual

Checks for existence of a file.

If acceptAbsPaths is TRUE a path starting with a 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.

Returns TRUE if the file exists, otherwise FALSE.

See also
QFileInfo::exists(), QFile::exists()

Definition at line 939 of file qdir.cpp.

940 {
941  if ( name.isEmpty() ) {
942 #if defined(CHECK_NULL)
943  qWarning( "QDir::exists: Empty or null file name" );
944 #endif
945  return FALSE;
946  }
947  QString tmp = filePath( name, acceptAbsPath );
948  return QFile::exists( tmp );
949 }
bool isEmpty() const
Definition: qstring.h:682
const bool FALSE
Definition: qglobal.h:370
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
bool exists() const
Definition: qfile.cpp:183
string tmp
Definition: languages.py:63
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
QString QDir::filePath ( const QString fileName,
bool  acceptAbsPath = TRUE 
) const
virtual

Returns the path name of a file in the directory. Does NOT check if the file actually exists in the directory. 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()).

If acceptAbsPath is TRUE a fileName starting with a separator ('/') will be returned without change. If acceptAbsPath is FALSE an absolute path will be appended to the directory path.

See also
absFilePath(), isRelative(), canonicalPath()

Definition at line 323 of file qdir.cpp.

325 {
326  if ( acceptAbsPath && !isRelativePath(fileName) )
327  return QString(fileName);
328 
329  QString tmp = dPath;
330  if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName &&
331  fileName[0] != '/') )
332  tmp += '/';
333  tmp += fileName;
334  return tmp;
335 }
bool isEmpty() const
Definition: qstring.h:682
QString dPath
Definition: qdir.h:187
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
fileName
Definition: dumpTree.py:9
uint length() const
Definition: qstring.h:679
string tmp
Definition: languages.py:63
QDir::FilterSpec QDir::filter ( ) const
inline

Returns the value set by setFilter()

Definition at line 208 of file qdir.h.

209 {
210  return filtS;
211 }
FilterSpec filtS
Definition: qdir.h:191
QDir QDir::home ( )
static

Returns the home directory.

See also
homeDirPath()

Definition at line 988 of file qdir.cpp.

989 {
990  return QDir( homeDirPath() );
991 }
static QString homeDirPath()
Definition: qdir_unix.cpp:69
QDir()
Definition: qdir.cpp:137
QString QDir::homeDirPath ( )
static

Returns the absolute path for the user's home directory,

See also
home()

Definition at line 69 of file qdir_unix.cpp.

70 {
71  QString d;
72  d = QFile::decodeName(getenv("HOME"));
73  slashify( d );
74  if ( d.isNull() )
75  d = rootDirPath();
76  return d;
77 }
static void slashify(QString &)
Definition: qdir_unix.cpp:65
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
std::string getenv(std::string const &name)
Definition: getenv.cc:15
static QString rootDirPath()
Definition: qdir_unix.cpp:163
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
bool isNull() const
Definition: qstring.h:379
void QDir::init ( )
private

Definition at line 205 of file qdir.cpp.

206 {
207  fList = 0;
208  fiList = 0;
210  dirty = TRUE;
211  allDirs = FALSE;
212  filtS = All;
214 }
QString nameFilt
Definition: qdir.h:190
Definition: qdir.h:59
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
SortSpec
Definition: qdir.h:74
const bool FALSE
Definition: qglobal.h:370
ChannelGroupService::Name Name
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
QStringList * fList
Definition: qdir.h:188
uint allDirs
Definition: qdir.h:194
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
QFileInfoList * fiList
Definition: qdir.h:189
bool QDir::isReadable ( ) const
virtual

Definition at line 109 of file qdir_unix.cpp.

110 {
111  return ACCESS( QFile::encodeName(dPath), R_OK | X_OK ) == 0;
112 }
QString dPath
Definition: qdir.h:187
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
#define ACCESS
Definition: qfiledefs_p.h:216
bool QDir::isRelative ( ) const
virtual

Returns TRUE if the directory path is relative to the current directory, FALSE if the path is absolute (e.g. under UNIX a path is relative if it does not start with a '/').

According to Einstein this function should always return TRUE.

See also
convertToAbs()

Definition at line 836 of file qdir.cpp.

837 {
838  return isRelativePath( dPath );
839 }
QString dPath
Definition: qdir.h:187
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
bool QDir::isRelativePath ( const QString path)
static

Definition at line 169 of file qdir_unix.cpp.

170 {
171  int len = path.length();
172  if ( len == 0 )
173  return TRUE;
174  return path[0] != '/';
175 }
uint length() const
Definition: qstring.h:679
const bool TRUE
Definition: qglobal.h:371
bool QDir::isRoot ( ) const
virtual

Definition at line 114 of file qdir_unix.cpp.

115 {
116  return dPath == QString::fromLatin1("/");
117 }
QString dPath
Definition: qdir.h:187
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
bool QDir::match ( const QStringList filters,
const QString fileName 
)
static

Returns TRUE if the fileName matches one of the wildcards in the list filters.

See also
QRegExp

Definition at line 1036 of file qdir.cpp.

1037 {
1038  QStringList::ConstIterator sit = filters.begin();
1039  bool matched = FALSE;
1040  for ( ; sit != filters.end(); ++sit ) {
1041  QRegExp regexp( (*sit).data(), FALSE, TRUE );
1042  if ( regexp.match( fileName.data() ) != -1 ) {
1043  matched = TRUE;
1044  break;
1045  }
1046  }
1047 
1048  return matched;
1049 }
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
Iterator end()
Definition: qvaluelist.h:363
const bool FALSE
Definition: qglobal.h:370
const char * data() const
Definition: qstring.h:542
Iterator begin()
Definition: qvaluelist.h:361
const bool TRUE
Definition: qglobal.h:371
bool QDir::match ( const QString filter,
const QString fileName 
)
static

Returns TRUE if the fileName matches the wildcard filter. Filter may also contain multiple wildcards separated by spaces or semicolons.

See also
QRegExp

Definition at line 1058 of file qdir.cpp.

1059 {
1060  QStringList lst = qt_makeFilterList( filter );
1061  return match( lst, fileName );
1062 }
static bool match(const QStringList &filters, const QString &fileName)
Definition: qdir.cpp:1036
A list of strings.
Definition: qstringlist.h:51
QStringList qt_makeFilterList(const QString &filter)
Definition: qdir.cpp:1010
bool QDir::matchAllDirs ( ) const
inline

Returns the value set by setMatchAllDirs()

See also
setMatchAllDirs()

Definition at line 218 of file qdir.h.

219 {
220  return allDirs;
221 }
uint allDirs
Definition: qdir.h:194
bool QDir::mkdir ( const QString dirName,
bool  acceptAbsPath = TRUE 
) const
virtual

Definition at line 98 of file qdir_unix.cpp.

99 {
100  return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 )
101  == 0;
102 }
#define MKDIR
Definition: qfiledefs_p.h:224
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
QString QDir::nameFilter ( ) const
inline

Returns the string set by setNameFilter()

Definition at line 203 of file qdir.h.

204 {
205  return nameFilt;
206 }
QString nameFilt
Definition: qdir.h:190
bool QDir::operator!= ( const QDir d) const
inlinevirtual

Returns TRUE if the d and this dir have different path or different sort/filter settings, otherwise FALSE.

Definition at line 223 of file qdir.h.

224 {
225  return !(*this == d);
226 }
QDir & QDir::operator= ( const QDir d)

Makes a copy of d and assigns it to this QDir.

Definition at line 857 of file qdir.cpp.

858 {
859  dPath = d.dPath;
860  delete fList;
861  fList = 0;
862  delete fiList;
863  fiList = 0;
864  nameFilt = d.nameFilt;
865  dirty = TRUE;
866  allDirs = d.allDirs;
867  filtS = d.filtS;
868  sortS = d.sortS;
869  return *this;
870 }
QString nameFilt
Definition: qdir.h:190
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
QString dPath
Definition: qdir.h:187
QStringList * fList
Definition: qdir.h:188
uint allDirs
Definition: qdir.h:194
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
QFileInfoList * fiList
Definition: qdir.h:189
QDir & QDir::operator= ( const QString path)

Sets the directory path to be the given path.

Definition at line 876 of file qdir.cpp.

877 {
878  dPath = cleanDirPath( path );
879  dirty = TRUE;
880  return *this;
881 }
static QString cleanDirPath(const QString &dirPath)
Definition: qdir.cpp:1077
QString dPath
Definition: qdir.h:187
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
bool QDir::operator== ( const QDir d) const
virtual

Returns TRUE if the d and this dir have the same path and all sort and filter settings are equal, otherwise FALSE.

Definition at line 895 of file qdir.cpp.

896 {
897  return dPath == d.dPath &&
898  nameFilt == d.nameFilt &&
899  allDirs == d.allDirs &&
900  filtS == d.filtS &&
901  sortS == d.sortS;
902 }
QString nameFilt
Definition: qdir.h:190
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
QString dPath
Definition: qdir.h:187
uint allDirs
Definition: qdir.h:194
QString QDir::operator[] ( int  index) const

Returns the file name at position index in the list of found file names. Equivalent to entryList().at(index).

Returns null if the index is out of range or if the entryList() function failed.

See also
count(), entryList()

Definition at line 657 of file qdir.cpp.

658 {
659  entryList();
660  return fList && index >= 0 && index < (int)fList->count() ?
661  (*fList)[index] : QString::null;
662 }
uint count() const
Definition: qvaluelist.h:394
QStringList * fList
Definition: qdir.h:188
static const Null null
Definition: qstring.h:376
virtual QStringList entryList(int filterSpec=DefaultFilter, int sortSpec=DefaultSort) const
Definition: qdir.cpp:717
QString QDir::path ( ) const
inlinevirtual

Returns the path, this may contain symbolic links, but never contains redundant ".", ".." or multiple separators.

The returned path can be either absolute or relative (see setPath()).

See also
setPath(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath(), convertSeparators()

Definition at line 198 of file qdir.h.

199 {
200  return dPath;
201 }
QString dPath
Definition: qdir.h:187
bool QDir::readDirEntries ( const QString nameFilter,
int  FilterSpec,
int  SortSpec 
)
privatevirtual

Definition at line 177 of file qdir_unix.cpp.

179 {
180  int i;
181  if ( !fList ) {
182  fList = new QStringList;
183  CHECK_PTR( fList );
184  fiList = new QFileInfoList;
185  CHECK_PTR( fiList );
187  } else {
188  fList->clear();
189  fiList->clear();
190  }
191 
192  QStringList filters = qt_makeFilterList( nameFilter );
193 
194  bool doDirs = (filterSpec & Dirs) != 0;
195  bool doFiles = (filterSpec & Files) != 0;
196  bool noSymLinks = (filterSpec & NoSymLinks) != 0;
197  bool doReadable = (filterSpec & Readable) != 0;
198  bool doWritable = (filterSpec & Writable) != 0;
199  bool doExecable = (filterSpec & Executable) != 0;
200  bool doHidden = (filterSpec & Hidden) != 0;
201 
202 #if defined(_OS_OS2EMX_)
203  //QRegExp wc( nameFilter, FALSE, TRUE ); // wild card, case insensitive
204 #else
205  //QRegExp wc( nameFilter, TRUE, TRUE ); // wild card, case sensitive
206 #endif
207  QFileInfo fi;
208  DIR *dir;
209  dirent *file;
210 
211  dir = opendir( QFile::encodeName(dPath) );
212  if ( !dir ) {
213 #if defined(CHECK_NULL)
214  qWarning( "QDir::readDirEntries: Cannot read the directory: %s",
216 #endif
217  return FALSE;
218  }
219 
220  while ( (file = readdir(dir)) ) {
221  QString fn = QFile::decodeName(file->d_name);
222  fi.setFile( *this, fn );
223  if ( !match( filters, fn ) && !(allDirs && fi.isDir()) )
224  continue;
225  if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) ) {
226  if ( noSymLinks && fi.isSymLink() )
227  continue;
228  if ( (filterSpec & RWEMask) != 0 )
229  if ( (doReadable && !fi.isReadable()) ||
230  (doWritable && !fi.isWritable()) ||
231  (doExecable && !fi.isExecutable()) )
232  continue;
233  if ( !doHidden && fn[0] == '.' &&
234  fn != QString::fromLatin1(".")
235  && fn != QString::fromLatin1("..") )
236  continue;
237  fiList->append( new QFileInfo( fi ) );
238  }
239  }
240  if ( closedir(dir) != 0 ) {
241 #if defined(CHECK_NULL)
242  qWarning( "QDir::readDirEntries: Cannot close the directory: %s",
243  dPath.local8Bit().data() );
244 #endif
245  }
246 
247  // Sort...
248  if(fiList->count()) {
249  QDirSortItem* si= new QDirSortItem[fiList->count()];
250  QFileInfo* itm;
251  i=0;
252  for (itm = fiList->first(); itm; itm = fiList->next())
253  si[i++].item = itm;
254  qt_cmp_si_sortSpec = sortSpec;
255  qsort( si, i, sizeof(si[0]), qt_cmp_si );
256  // put them back in the list
258  fiList->clear();
259  int j;
260  for ( j=0; j<i; j++ ) {
261  fiList->append( si[j].item );
262  fList->append( si[j].item->fileName() );
263  }
264  delete [] si;
266  }
267 
268  if ( filterSpec == (FilterSpec)filtS && sortSpec == (SortSpec)sortS &&
269  nameFilter == nameFilt )
270  dirty = FALSE;
271  else
272  dirty = TRUE;
273  return TRUE;
274 }
QString nameFilt
Definition: qdir.h:190
static bool match(const QStringList &filters, const QString &fileName)
Definition: qdir.cpp:1036
Iterator append(const T &x)
Definition: qvaluelist.h:372
SortSpec sortS
Definition: qdir.h:192
FilterSpec filtS
Definition: qdir.h:191
int qt_cmp_si(const void *, const void *)
Definition: qdir.cpp:1145
type * first()
Definition: qinternallist.h:87
SortSpec
Definition: qdir.h:74
void clear()
Definition: qvaluelist.h:396
const bool FALSE
Definition: qglobal.h:370
QString dPath
Definition: qdir.h:187
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
string dir
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
bool isFile() const
QCString local8Bit() const
Definition: qstring.cpp:14569
bool isSymLink() const
QInternalList< QFileInfo > QFileInfoList
Definition: qdir.h:47
QAsciiDict< Entry > fn
A list of strings.
Definition: qstringlist.h:51
void setFile(const QString &file)
Definition: qfileinfo.cpp:219
void append(const type *d)
Definition: qinternallist.h:61
const char * data() const
Definition: qcstring.h:207
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
type * next()
Definition: qinternallist.h:89
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
bool isWritable() const
Definition: qfileinfo.cpp:415
void setAutoDelete(bool enable)
Definition: qcollection.h:55
QStringList * fList
Definition: qdir.h:188
#define CHECK_PTR(p)
Definition: qglobal.h:601
int qt_cmp_si_sortSpec
Definition: qdir.cpp:1139
QStringList qt_makeFilterList(const QString &filter)
Definition: qdir.cpp:1010
uint allDirs
Definition: qdir.h:194
bool isExecutable() const
Definition: qfileinfo.cpp:425
uint dirty
Definition: qdir.h:193
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
uint count() const
Definition: qinternallist.h:56
FilterSpec
Definition: qdir.h:55
def filters(nticks=9600, tick=0.5 *units.us, npitches=3000, pitch=1.0)
Definition: __init__.py:555
bool isDir() const
const bool TRUE
Definition: qglobal.h:371
QFileInfoList * fiList
Definition: qdir.h:189
bool isReadable() const
Definition: qfileinfo.cpp:405
bool QDir::remove ( const QString fileName,
bool  acceptAbsPath = TRUE 
)
virtual

Removes a file.

If acceptAbsPath is TRUE a path starting with a 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.

Returns TRUE if successful, otherwise FALSE.

Definition at line 915 of file qdir.cpp.

916 {
917  if ( fileName.isEmpty() ) {
918 #if defined(CHECK_NULL)
919  qWarning( "QDir::remove: Empty or null file name" );
920 #endif
921  return FALSE;
922  }
923  QString p = filePath( fileName, acceptAbsPath );
924  return QFile::remove( p );
925 }
bool isEmpty() const
Definition: qstring.h:682
const bool FALSE
Definition: qglobal.h:370
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
p
Definition: test.py:223
bool remove()
Definition: qfile.cpp:205
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
bool QDir::rename ( const QString name,
const QString newName,
bool  acceptAbsPaths = TRUE 
)
virtual

Definition at line 119 of file qdir_unix.cpp.

121 {
122  if ( name.isEmpty() || newName.isEmpty() ) {
123 #if defined(CHECK_NULL)
124  qWarning( "QDir::rename: Empty or null file name(s)" );
125 #endif
126  return FALSE;
127  }
128  QString fn1 = filePath( name, acceptAbsPaths );
129  QString fn2 = filePath( newName, acceptAbsPaths );
131  QFile::encodeName(fn2) ) == 0;
132 }
bool isEmpty() const
Definition: qstring.h:682
const bool FALSE
Definition: qglobal.h:370
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
def rename(src, dest)
bool QDir::rmdir ( const QString dirName,
bool  acceptAbsPath = TRUE 
) const
virtual

Definition at line 104 of file qdir_unix.cpp.

105 {
106  return RMDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0;
107 }
#define RMDIR
Definition: qfiledefs_p.h:225
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
QDir QDir::root ( )
static

Returns the root directory.

See also
rootDirPath() drives()

Definition at line 998 of file qdir.cpp.

999 {
1000  return QDir( rootDirPath() );
1001 }
QDir()
Definition: qdir.cpp:137
static QString rootDirPath()
Definition: qdir_unix.cpp:163
QString QDir::rootDirPath ( )
static

Definition at line 163 of file qdir_unix.cpp.

164 {
165  QString d = QString::fromLatin1( "/" );
166  return d;
167 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
char QDir::separator ( )
static

Returns the native directory separator; '/' under UNIX and '\' under MS-DOS, Windows NT and OS/2.

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.

Definition at line 960 of file qdir.cpp.

961 {
962 #if defined(_OS_UNIX_)
963  return '/';
964 #elif defined (_OS_FATFS_)
965  return '\\';
966 #elif defined (_OS_MAC_)
967  return ':';
968 #else
969  return '/';
970 #endif
971 }
bool QDir::setCurrent ( const QString path)
static

Definition at line 134 of file qdir_unix.cpp.

135 {
136  int r;
137  r = CHDIR( QFile::encodeName(path) );
138  return r >= 0;
139 }
#define CHDIR
Definition: qfiledefs_p.h:222
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
void QDir::setFilter ( int  filterSpec)
virtual

Sets the filter used by entryList() and entryInfoList(). The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList().

See also
filter(), setNameFilter()

Definition at line 538 of file qdir.cpp.

539 {
540  if ( filtS == (FilterSpec) filterSpec )
541  return;
542  filtS = (FilterSpec) filterSpec;
543  dirty = TRUE;
544 }
FilterSpec filtS
Definition: qdir.h:191
uint dirty
Definition: qdir.h:193
FilterSpec
Definition: qdir.h:55
const bool TRUE
Definition: qglobal.h:371
void QDir::setMatchAllDirs ( bool  enable)
virtual

If enable is TRUE, all directories will be listed (even if they do not match the filter or the name filter), otherwise only matched directories will be listed.

Bug:
Currently, directories that do not match the filter will not be included (the name filter will be ignored as expected).
See also
matchAllDirs()

Definition at line 626 of file qdir.cpp.

627 {
628  if ( (bool)allDirs == enable )
629  return;
630  allDirs = enable;
631  dirty = TRUE;
632 }
uint allDirs
Definition: qdir.h:194
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
void QDir::setNameFilter ( const QString nameFilter)
virtual

Sets the name filter used by entryList() and entryInfoList().

The name filter is a wildcarding filter that understands "*" and "?" wildcards, You may specify several filter entries separated by a " " or a ";". If you want entryList() and entryInfoList() to list all files ending with ".cpp" and all files ending with ".h", you simply call dir.setNameFilter("*.cpp *.h") or dir.setNameFilter("*.cpp;*.h")

See also
nameFilter(), setFilter()

Definition at line 486 of file qdir.cpp.

487 {
489  if ( nameFilt.isEmpty() )
491  dirty = TRUE;
492 }
QString nameFilt
Definition: qdir.h:190
QString nameFilter() const
Definition: qdir.h:203
bool isEmpty() const
Definition: qstring.h:682
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
void QDir::setPath ( const QString path)
virtual

Sets the path of the directory. The path is cleaned of redundant ".", ".." and multiple separators. No check is made to ensure that a directory with this path exists.

The path can be either absolute or relative. Absolute paths begin with the directory separator ('/') or a drive specification (not applicable to UNIX). 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". You can use the function isRelative() to check if a QDir is using a relative or an absolute file path. You can call the function convertToAbs() to convert a relative QDir to an absolute one.

See also
path(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath(), isRelative(), convertToAbs()

Definition at line 248 of file qdir.cpp.

249 {
250  dPath = cleanDirPath( path );
251  if ( dPath.isEmpty() )
252  dPath = QString::fromLatin1(".");
253  dirty = TRUE;
254 }
static QString cleanDirPath(const QString &dirPath)
Definition: qdir.cpp:1077
bool isEmpty() const
Definition: qstring.h:682
QString dPath
Definition: qdir.h:187
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
void QDir::setSorting ( int  sortSpec)
virtual

Sets the sorting order used by entryList() and entryInfoList().

The sortSpec is specified by or-ing values from the enum SortSpec. The different values are:

One of these:

Name
Sort by name (alphabetical order).
Time
Sort by time (most recent first).
Size
Sort by size (largest first).
Unsorted

Use the operating system order (UNIX does NOT sort alphabetically).

ORed with zero or more of these:

DirsFirst
Always put directory names first.
Reversed
Reverse sort order.
IgnoreCase
Ignore case when sorting by name.

Definition at line 600 of file qdir.cpp.

601 {
602  if ( sortS == (SortSpec) sortSpec )
603  return;
604  sortS = (SortSpec) sortSpec;
605  dirty = TRUE;
606 }
SortSpec sortS
Definition: qdir.h:192
SortSpec
Definition: qdir.h:74
uint dirty
Definition: qdir.h:193
const bool TRUE
Definition: qglobal.h:371
void QDir::slashify ( QString n)
staticprivate

Definition at line 65 of file qdir_unix.cpp.

66 {
67 }
QDir::SortSpec QDir::sorting ( ) const
inline

Returns the value set by setSorting()

See also
setSorting()

Definition at line 213 of file qdir.h.

214 {
215  return sortS;
216 }
SortSpec sortS
Definition: qdir.h:192

Member Data Documentation

uint QDir::allDirs
private

Definition at line 194 of file qdir.h.

uint QDir::dirty
private

Definition at line 193 of file qdir.h.

QString QDir::dPath
private

Definition at line 187 of file qdir.h.

QFileInfoList* QDir::fiList
private

Definition at line 189 of file qdir.h.

FilterSpec QDir::filtS
private

Definition at line 191 of file qdir.h.

QStringList* QDir::fList
private

Definition at line 188 of file qdir.h.

QString QDir::nameFilt
private

Definition at line 190 of file qdir.h.

SortSpec QDir::sortS
private

Definition at line 192 of file qdir.h.


The documentation for this class was generated from the following files: