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

The QFileInfo class provides system-independent file information. More...

#include <qfileinfo.h>

Public Types

enum  PermissionSpec {
  ReadUser = 0400, WriteUser = 0200, ExeUser = 0100, ReadGroup = 0040,
  WriteGroup = 0020, ExeGroup = 0010, ReadOther = 0004, WriteOther = 0002,
  ExeOther = 0001
}
 

Public Member Functions

 QFileInfo ()
 
 QFileInfo (const QString &file)
 
 QFileInfo (const QFile &)
 
 QFileInfo (const QDir &, const QString &fileName)
 
 QFileInfo (const QFileInfo &)
 
 ~QFileInfo ()
 
QFileInfooperator= (const QFileInfo &)
 
void setFile (const QString &file)
 
void setFile (const QFile &)
 
void setFile (const QDir &, const QString &fileName)
 
bool exists () const
 
void refresh () const
 
bool caching () const
 
void setCaching (bool)
 
QString filePath () const
 
QString fileName () const
 
QString absFilePath () const
 
QString baseName () const
 
QString extension (bool complete=TRUE) const
 
QString dirPath (bool absPath=FALSE) const
 
QDir dir (bool absPath=FALSE) const
 
bool isReadable () const
 
bool isWritable () const
 
bool isExecutable () const
 
bool isRelative () const
 
bool convertToAbs ()
 
bool isFile () const
 
bool isDir () const
 
bool isSymLink () const
 
QString readLink () const
 
QString owner () const
 
uint ownerId () const
 
QString group () const
 
uint groupId () const
 
bool permission (int permissionSpec) const
 
uint size () const
 
QDateTime lastModified () const
 
QDateTime lastRead () const
 

Private Member Functions

void doStat () const
 

Static Private Member Functions

static void slashify (QString &)
 
static void makeAbs (QString &)
 

Private Attributes

QString fn
 
QFileInfoCachefic
 
bool cache
 

Detailed Description

The QFileInfo class provides system-independent file information.

QFileInfo provides information about a file's name and position (path) in the file system, its access rights and whether it is a directory or a symbolic link. Its size and last modified/read times are also available.

To speed up performance QFileInfo caches information about the file. Since files can be changed by other users or programs, or even by other parts of the same program there is a function that refreshes the file information; refresh(). If you would rather like a QFileInfo to access the file system every time you request information from it, you can call the function setCaching( FALSE ).

A QFileInfo 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 QFileInfo is using a relative or an absolute file path. You can call the function convertToAbs() to convert a relative QFileInfo to an absolute one.

If you need to read and traverse directories, see the QDir class.

Definition at line 51 of file qfileinfo.h.

Member Enumeration Documentation

Enumerator
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 

Definition at line 54 of file qfileinfo.h.

Constructor & Destructor Documentation

QFileInfo::QFileInfo ( )

Constructs a new empty QFileInfo.

Definition at line 83 of file qfileinfo.cpp.

84 {
85  fic = 0;
86  cache = TRUE;
87 }
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
const bool TRUE
Definition: qglobal.h:371
QFileInfo::QFileInfo ( const QString file)

Constructs a new QFileInfo that gives information about the given file. The string given can be an absolute or a relative file path.

See also
bool setFile(QString ), isRelative(), QDir::setCurrent(), QDir::isRelativePath()

Definition at line 97 of file qfileinfo.cpp.

98 {
99  fn = file;
100  slashify( fn );
101  fic = 0;
102  cache = TRUE;
103 }
static void slashify(QString &)
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
const bool TRUE
Definition: qglobal.h:371
QFileInfo::QFileInfo ( const QFile file)

Constructs a new QFileInfo that gives information about file.

If the file has a relative path, the QFileInfo will also have one.

See also
isRelative()

Definition at line 113 of file qfileinfo.cpp.

114 {
115  fn = file.name();
116  slashify( fn );
117  fic = 0;
118  cache = TRUE;
119 }
QString name() const
Definition: qfile.h:121
static void slashify(QString &)
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
const bool TRUE
Definition: qglobal.h:371
QFileInfo::QFileInfo ( const QDir d,
const QString fileName 
)

Constructs a new QFileInfo that gives information about the file named fileName in the directory d.

If the directory has a relative path, the QFileInfo will also have one.

See also
isRelative()

Definition at line 130 of file qfileinfo.cpp.

131 {
132  fn = d.filePath( fileName );
133  slashify( fn );
134  fic = 0;
135  cache = TRUE;
136 }
static void slashify(QString &)
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
const bool TRUE
Definition: qglobal.h:371
QFileInfo::QFileInfo ( const QFileInfo fi)

Constructs a new QFileInfo that is a copy of fi.

Definition at line 142 of file qfileinfo.cpp.

143 {
144  fn = fi.fn;
145  if ( fi.fic ) {
146  fic = new QFileInfoCache;
147  *fic = *fi.fic;
148  } else {
149  fic = 0;
150  }
151  cache = fi.cache;
152 }
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
QFileInfo::~QFileInfo ( )

Destructs the QFileInfo.

Definition at line 158 of file qfileinfo.cpp.

159 {
160  delete fic;
161 }
QFileInfoCache * fic
Definition: qfileinfo.h:127

Member Function Documentation

QString QFileInfo::absFilePath ( ) const

Returns the absolute path name.

The absolute path name is the file name including the absolute path. If the QFileInfo is absolute (i.e. not relative) this function will return the same string as filePath().

Note that this function can be time-consuming under UNIX. (in the order of milliseconds on a 486 DX2/66 running Linux).

See also
isRelative(), filePath()

Definition at line 410 of file qfileinfo_unix.cpp.

411 {
412  if ( QDir::isRelativePath(fn) ) {
414  tmp += '/';
415  tmp += fn;
416  makeAbs( tmp );
417  return QDir::cleanDirPath( tmp );
418  } else {
419  QString tmp = fn;
420  makeAbs( tmp );
421  return QDir::cleanDirPath( tmp );
422  }
423 
424 }
static QString cleanDirPath(const QString &dirPath)
Definition: qdir.cpp:1077
static void makeAbs(QString &)
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
QString fn
Definition: qfileinfo.h:126
static QString currentDirPath()
Definition: qdir_unix.cpp:141
string tmp
Definition: languages.py:63
QString QFileInfo::baseName ( ) const

Returns the base name of the file.

The base name consists of all characters in the file name up to (but not including) the first '.' character. The path is not included.

Example:

QFileInfo fi( "/tmp/abdomen.lower" );
QString base = fi.baseName(); // base = "abdomen"
See also
fileName(), extension()

Definition at line 341 of file qfileinfo.cpp.

342 {
343  QString tmp = fileName();
344  int pos = tmp.find( '.' );
345  if ( pos == -1 )
346  return tmp;
347  else
348  return tmp.left( pos );
349 }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString left(uint len) const
Definition: qstring.cpp:13199
string tmp
Definition: languages.py:63
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
QString fileName() const
bool QFileInfo::caching ( ) const
inline

Returns TRUE if caching is enabled.

See also
setCaching(), refresh()

Definition at line 132 of file qfileinfo.h.

133 {
134  return cache;
135 }
bool cache
Definition: qfileinfo.h:128
bool QFileInfo::convertToAbs ( )

Converts the file path name to an absolute path.

If it is already absolute nothing is done.

See also
filePath(), isRelative()

Definition at line 452 of file qfileinfo.cpp.

453 {
454  if ( isRelative() )
455  fn = absFilePath();
456  return QDir::isRelativePath( fn );
457 }
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
QString absFilePath() const
QString fn
Definition: qfileinfo.h:126
bool isRelative() const
Definition: qfileinfo.cpp:439
QDir QFileInfo::dir ( bool  absPath = FALSE) const

Returns the directory path of the file.

If the QFileInfo is relative and absPath is FALSE, the QDir will be relative, otherwise it will be absolute.

See also
dirPath(), filePath(), fileName(), isRelative()

Definition at line 393 of file qfileinfo.cpp.

394 {
395  return QDir( dirPath(absPath) );
396 }
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
QString dirPath(bool absPath=FALSE) const
QString QFileInfo::dirPath ( bool  absPath = FALSE) const

Returns the directory path of the file.

If absPath is TRUE an absolute path is always returned.

See also
dir(), filePath(), fileName(), isRelative()

Definition at line 358 of file qfileinfo_unix.cpp.

359 {
360  QString s;
361  if ( absPath )
362  s = absFilePath();
363  else
364  s = fn;
365  int pos = s.findRev( '/' );
366  if ( pos == -1 ) {
367  return QString::fromLatin1(".");
368  } else {
369  if ( pos == 0 )
370  return QString::fromLatin1( "/" );
371  return s.left( pos );
372  }
373 }
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 absFilePath() const
QString fn
Definition: qfileinfo.h:126
QString left(uint len) const
Definition: qstring.cpp:13199
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
static QCString * s
Definition: config.cpp:1042
void QFileInfo::doStat ( ) const
private

Definition at line 324 of file qfileinfo_unix.cpp.

325 {
326  QFileInfo *that = ((QFileInfo*)this); // mutable function
327  if ( !that->fic )
328  that->fic = new QFileInfoCache;
329  STATBUF *b = &that->fic->st;
330  that->fic->isSymLink = FALSE;
331 
332 #if defined(_OS_UNIX_) && defined(S_IFLNK)
333  if ( ::lstat(QFile::encodeName(fn),b) == 0 ) {
334  if ( S_ISLNK( b->st_mode ) )
335  that->fic->isSymLink = TRUE;
336  else
337  return;
338  }
339 #endif
340  int r;
341 
342  r = STAT( QFile::encodeName(fn), b );
343 
344  if ( r != 0 ) {
345  delete that->fic;
346  that->fic = 0;
347  }
348 }
#define STATBUF
Definition: qfiledefs_p.h:199
#define STAT
Definition: qfiledefs_p.h:201
const bool FALSE
Definition: qglobal.h:370
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
static bool * b
Definition: config.cpp:1043
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
const bool TRUE
Definition: qglobal.h:371
bool QFileInfo::exists ( ) const

Returns TRUE if the file pointed to exists, otherwise FALSE.

Definition at line 265 of file qfileinfo.cpp.

266 {
267  return qt_file_access( fn, F_OK );
268 }
QString fn
Definition: qfileinfo.h:126
bool qt_file_access(const QString &fn, int t)
Definition: qfile_unix.cpp:54
QString QFileInfo::extension ( bool  complete = TRUE) const

Returns the extension name of the file.

If complete is TRUE (the default), extension() returns the string of all characters in the file name after (but not including) the first '.' character. For a file named "archive.tar.gz" this returns "tar.gz".

If complete is FALSE, extension() returns the string of all characters in the file name after (but not including) the last '.' character. For a file named "archive.tar.gz" this returns "gz".

Example:

QFileInfo fi( "lex.yy.c" );
QString ext = fi.extension(); // ext = "yy.c"
QString ext = fi.extension( FALSE ); // ext = "c"
See also
fileName(), baseName()

Definition at line 374 of file qfileinfo.cpp.

375 {
376  QString s = fileName();
377  int pos = complete ? s.find( '.' ) : s.findRev( '.' );
378  if ( pos < 0 )
379  return QString::fromLatin1( "" );
380  else
381  return s.right( s.length() - pos - 1 );
382 }
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
uint length() const
Definition: qstring.h:679
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
int find(QChar c, int index=0, bool cs=TRUE) const
Definition: qstring.cpp:12902
QString fileName() const
static QCString * s
Definition: config.cpp:1042
QString right(uint len) const
Definition: qstring.cpp:13231
QString QFileInfo::fileName ( ) const

Returns the name of the file, the file path is not included.

Example:

QFileInfo fi( "/tmp/abdomen.lower" );
QString name = fi.fileName(); // name = "abdomen.lower"
See also
isRelative(), filePath(), baseName(), extension()

Definition at line 387 of file qfileinfo_unix.cpp.

388 {
389  int p = fn.findRev( '/' );
390  if ( p == -1 ) {
391  return fn;
392  } else {
393  return fn.mid(p+1);
394  }
395 }
QString mid(uint index, uint len=0xffffffff) const
Definition: qstring.cpp:13265
QString fn
Definition: qfileinfo.h:126
p
Definition: test.py:223
int findRev(QChar c, int index=-1, bool cs=TRUE) const
Definition: qstring.cpp:13021
QString QFileInfo::filePath ( ) const

Returns the name, i.e. the file name including the path (which can be absolute or relative).

See also
isRelative(), absFilePath()

Definition at line 321 of file qfileinfo.cpp.

322 {
323  return fn;
324 }
QString fn
Definition: qfileinfo.h:126
QString QFileInfo::group ( ) const

Returns the group the file belongs to.

On systems where files do not have groups this function always returns 0.

Note that this function can be time-consuming under UNIX (in the order of milliseconds on a 486 DX2/66 running Linux).

See also
groupId(), owner(), ownerId()

Definition at line 187 of file qfileinfo_unix.cpp.

188 {
189  struct group *gr = getgrgid( groupId() );
190  if ( gr )
191  return QFile::decodeName( gr->gr_name );
192  return QString::null;
193 }
uint groupId() const
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
QString group() const
static const Null null
Definition: qstring.h:376
uint QFileInfo::groupId ( ) const

Returns the id of the group the file belongs to.

On systems where files do not have groups this function always returns ((uind) -2).

See also
group(), owner(), ownerId()

Definition at line 204 of file qfileinfo_unix.cpp.

205 {
206  if ( !fic || !cache )
207  doStat();
208  if ( fic )
209  return fic->st.st_gid;
210  return nobodyID;
211 }
void doStat() const
QFileInfoCache * fic
Definition: qfileinfo.h:127
static const uint nobodyID
bool cache
Definition: qfileinfo.h:128
bool QFileInfo::isDir ( ) const

Returns TRUE if we are pointing to a directory or a symbolic link to a directory.

See also
isFile(), isSymLink()

Definition at line 88 of file qfileinfo_unix.cpp.

89 {
90  if ( !fic || !cache )
91  doStat();
92  return fic ? (fic->st.st_mode & STAT_MASK) == STAT_DIR : FALSE;
93 }
void doStat() const
const bool FALSE
Definition: qglobal.h:370
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
#define STAT_DIR
Definition: qfiledefs_p.h:205
#define STAT_MASK
Definition: qfiledefs_p.h:206
bool QFileInfo::isExecutable ( ) const

Returns TRUE if the file is executable.

See also
isReadable(), isWritable(), permission()

Definition at line 425 of file qfileinfo.cpp.

426 {
427  return qt_file_access( fn, X_OK );
428 }
QString fn
Definition: qfileinfo.h:126
bool qt_file_access(const QString &fn, int t)
Definition: qfile_unix.cpp:54
bool QFileInfo::isFile ( ) const

Returns TRUE if we are pointing to a real file.

See also
isDir(), isSymLink()

Definition at line 75 of file qfileinfo_unix.cpp.

76 {
77  if ( !fic || !cache )
78  doStat();
79  return fic ? (fic->st.st_mode & STAT_MASK) == STAT_REG : FALSE;
80 }
void doStat() const
const bool FALSE
Definition: qglobal.h:370
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
#define STAT_REG
Definition: qfiledefs_p.h:204
#define STAT_MASK
Definition: qfiledefs_p.h:206
bool QFileInfo::isReadable ( ) const

Returns TRUE if the file is readable.

See also
isWritable(), isExecutable(), permission()

Definition at line 405 of file qfileinfo.cpp.

406 {
407  return qt_file_access( fn, R_OK );
408 }
QString fn
Definition: qfileinfo.h:126
bool qt_file_access(const QString &fn, int t)
Definition: qfile_unix.cpp:54
bool QFileInfo::isRelative ( ) const

Returns TRUE if the file path name 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.

Definition at line 439 of file qfileinfo.cpp.

440 {
441  return QDir::isRelativePath( fn );
442 }
static bool isRelativePath(const QString &path)
Definition: qdir_unix.cpp:169
QString fn
Definition: qfileinfo.h:126
bool QFileInfo::isSymLink ( ) const

Returns TRUE if we are pointing to a symbolic link.

See also
isFile(), isDir(), readLink()

Definition at line 100 of file qfileinfo_unix.cpp.

101 {
102  if ( !fic || !cache )
103  doStat();
104  return fic ? fic->isSymLink : FALSE;
105 }
void doStat() const
const bool FALSE
Definition: qglobal.h:370
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
bool QFileInfo::isWritable ( ) const

Returns TRUE if the file is writable.

See also
isReadable(), isExecutable(), permission()

Definition at line 415 of file qfileinfo.cpp.

416 {
417  return qt_file_access( fn, W_OK );
418 }
QString fn
Definition: qfileinfo.h:126
bool qt_file_access(const QString &fn, int t)
Definition: qfile_unix.cpp:54
QDateTime QFileInfo::lastModified ( ) const

Returns the date and time when the file was last modified.

See also
lastRead()

Definition at line 294 of file qfileinfo_unix.cpp.

295 {
296  QDateTime dt;
297  if ( !fic || !cache )
298  doStat();
299  if ( fic )
300  dt.setTime_t( (uint)fic->st.st_mtime );
301  return dt;
302 }
void doStat() const
void setTime_t(uint secsSince1Jan1970UTC)
Definition: qdatetime.cpp:1142
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
The QDateTime class provides date and time functions.
Definition: qdatetime.h:161
unsigned uint
Definition: qglobal.h:351
QDateTime QFileInfo::lastRead ( ) const

Returns the date and time when the file was last read (accessed).

On systems that do not support last read times, the modification time is returned.

See also
lastModified()

Definition at line 313 of file qfileinfo_unix.cpp.

314 {
315  QDateTime dt;
316  if ( !fic || !cache )
317  doStat();
318  if ( fic )
319  dt.setTime_t( (uint)fic->st.st_atime );
320  return dt;
321 }
void doStat() const
void setTime_t(uint secsSince1Jan1970UTC)
Definition: qdatetime.cpp:1142
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
The QDateTime class provides date and time functions.
Definition: qdatetime.h:161
unsigned uint
Definition: qglobal.h:351
void QFileInfo::makeAbs ( QString )
staticprivate

Definition at line 64 of file qfileinfo_unix.cpp.

65 {
66  return;
67 }
QFileInfo & QFileInfo::operator= ( const QFileInfo fi)

Makes a copy of fi and assigns it to this QFileInfo.

Definition at line 168 of file qfileinfo.cpp.

169 {
170  fn = fi.fn;
171  if ( !fi.fic ) {
172  delete fic;
173  fic = 0;
174  } else {
175  if ( !fic ) {
176  fic = new QFileInfoCache;
177  CHECK_PTR( fic );
178  }
179  *fic = *fi.fic;
180  }
181  cache = fi.cache;
182  return *this;
183 }
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
#define CHECK_PTR(p)
Definition: qglobal.h:601
QString QFileInfo::owner ( ) const

Returns the owner of the file.

On systems where files do not have owners this function returns 0.

Note that this function can be time-consuming under UNIX. (in the order of milliseconds on a 486 DX2/66 running Linux).

See also
ownerId(), group(), groupId()

Returns the owner of the file.

On systems where files do not have owners this function returns a null string.

Note that this function can be time-consuming under UNIX. (in the order of milliseconds on a 486 DX2/66 running Linux).

See also
ownerId(), group(), groupId()

Definition at line 150 of file qfileinfo_unix.cpp.

151 {
152  passwd *pw = getpwuid( ownerId() );
153  if ( pw )
154  return QFile::decodeName( pw->pw_name );
155  return QString::null;
156 }
uint ownerId() const
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
static const Null null
Definition: qstring.h:376
uint QFileInfo::ownerId ( ) const

Returns the id of the owner of the file.

On systems where files do not have owners this function returns ((uint) -2).

See also
owner(), group(), groupId()

Definition at line 166 of file qfileinfo_unix.cpp.

167 {
168  if ( !fic || !cache )
169  doStat();
170  if ( fic )
171  return fic->st.st_uid;
172  return nobodyID;
173 }
void doStat() const
QFileInfoCache * fic
Definition: qfileinfo.h:127
static const uint nobodyID
bool cache
Definition: qfileinfo.h:128
bool QFileInfo::permission ( int  permissionSpec) const

Tests for file permissions. The permissionSpec argument can be several flags of type PermissionSpec or'ed together to check for permission combinations.

On systems where files do not have permissions this function always returns TRUE.

Example:

QFileInfo fi( "/tmp/tonsils" );
if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) )
qWarning( "Tonsils can be changed by me, and the group can read them.");
qWarning( "Danger! Tonsils can be changed by the group or others!" );
See also
isReadable(), isWritable(), isExecutable()

Definition at line 236 of file qfileinfo_unix.cpp.

237 {
238  if ( !fic || !cache )
239  doStat();
240  if ( fic ) {
241  uint mask = 0;
242  if ( permissionSpec & ReadUser)
243  mask |= S_IRUSR;
244  if ( permissionSpec & WriteUser)
245  mask |= S_IWUSR;
246  if ( permissionSpec & ExeUser)
247  mask |= S_IXUSR;
248  if ( permissionSpec & ReadGroup)
249  mask |= S_IRGRP;
250  if ( permissionSpec & WriteGroup)
251  mask |= S_IWGRP;
252  if ( permissionSpec & ExeGroup)
253  mask |= S_IXGRP;
254  if ( permissionSpec & ReadOther)
255  mask |= S_IROTH;
256  if ( permissionSpec & WriteOther)
257  mask |= S_IWOTH;
258  if ( permissionSpec & ExeOther)
259  mask |= S_IXOTH;
260  if ( mask ) {
261  return (fic->st.st_mode & mask) == mask;
262  } else {
263 #if defined(CHECK_NULL)
264  qWarning( "QFileInfo::permission: permissionSpec is 0" );
265 #endif
266  return TRUE;
267  }
268  } else {
269  return FALSE;
270  }
271 }
void doStat() const
const bool FALSE
Definition: qglobal.h:370
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
QString QFileInfo::readLink ( ) const

Returns the name a symlink points to, or a null QString if the object does not refer to a symbolic link.

This name may not represent an existing file; it is only a string. QFileInfo::exists() returns TRUE if the symlink points to an existing file.

See also
exists(), isSymLink(), isDir(), isFile()

Definition at line 119 of file qfileinfo_unix.cpp.

120 {
121  QString r;
122 
123 #if defined(_OS_UNIX_) && !defined(_OS_OS2EMX_)
124  char s[PATH_MAX+1];
125  if ( !isSymLink() )
126  return QString();
127  int len = (int)readlink( QFile::encodeName(fn).data(), s, PATH_MAX );
128  if ( len >= 0 ) {
129  s[len] = '\0';
130  r = QFile::decodeName(s);
131  }
132 #endif
133 
134  return r;
135 }
#define PATH_MAX
Definition: qfiledefs_p.h:92
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
bool isSymLink() const
QString fn
Definition: qfileinfo.h:126
const char * data() const
Definition: qcstring.h:207
static QCString encodeName(const QString &fileName)
Definition: qfile.cpp:494
static QString decodeName(const QCString &localFileName)
Definition: qfile.cpp:529
static QCString * s
Definition: config.cpp:1042
void QFileInfo::refresh ( ) const

Refresh the information about the file, i.e. read in information from the file system the next time a cached property is fetched.

See also
setCaching()

Definition at line 277 of file qfileinfo.cpp.

278 {
279  QFileInfo *that = (QFileInfo*)this; // Mutable function
280  delete that->fic;
281  that->fic = 0;
282 }
QFileInfoCache * fic
Definition: qfileinfo.h:127
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:51
void QFileInfo::setCaching ( bool  enable)

Enables caching of file information if enable is TRUE, or disables it if enable is FALSE.

When caching is enabled, QFileInfo reads the file information the first time

Caching is enabled by default.

See also
refresh(), caching()

Definition at line 302 of file qfileinfo.cpp.

303 {
304  if ( cache == enable )
305  return;
306  cache = enable;
307  if ( cache ) {
308  delete fic;
309  fic = 0;
310  }
311 }
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
void QFileInfo::setFile ( const QString file)

Sets the file to obtain information about.

The string given can be an absolute or a relative file path. Absolute file paths begin with the directory separator (e.g. '/' under UNIX) 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.

Example:

#include <qfileinfo.h>
#include <qdir.h>
void test()
{
QString absolute = "/liver/aorta";
QString relative = "liver/aorta";
QFileInfo fi1( absolute );
QFileInfo fi2( relative );
// fi1 and fi2 now point to the same file
QDir::setCurrent( "/tmp" );
// fi1 now points to "/liver/aorta",
// while fi2 points to "/tmp/liver/aorta"
}
See also
isRelative(), QDir::setCurrent(), QDir::isRelativePath()

Definition at line 219 of file qfileinfo.cpp.

220 {
221  fn = file;
222  slashify( fn );
223  delete fic;
224  fic = 0;
225 }
static void slashify(QString &)
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
void QFileInfo::setFile ( const QFile file)

Sets the file to obtain information about.

If the file has a relative path, the QFileInfo will also have one.

See also
isRelative()

Definition at line 235 of file qfileinfo.cpp.

236 {
237  fn = file.name();
238  slashify( fn );
239  delete fic;
240  fic = 0;
241 }
QString name() const
Definition: qfile.h:121
static void slashify(QString &)
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
void QFileInfo::setFile ( const QDir d,
const QString fileName 
)

Sets the file to obtains information about to fileName in the directory d.

If the directory has a relative path, the QFileInfo will also have one.

See also
isRelative()

Definition at line 252 of file qfileinfo.cpp.

253 {
254  fn = d.filePath( fileName );
255  slashify( fn );
256  delete fic;
257  fic = 0;
258 }
static void slashify(QString &)
QString fn
Definition: qfileinfo.h:126
QFileInfoCache * fic
Definition: qfileinfo.h:127
virtual QString filePath(const QString &fileName, bool acceptAbsPath=TRUE) const
Definition: qdir.cpp:323
uint QFileInfo::size ( ) const

Returns the file size in bytes, or 0 if the file does not exist if the size cannot be fetched.

Definition at line 278 of file qfileinfo_unix.cpp.

279 {
280  if ( !fic || !cache )
281  doStat();
282  if ( fic )
283  return (uint)fic->st.st_size;
284  else
285  return 0;
286 }
void doStat() const
QFileInfoCache * fic
Definition: qfileinfo.h:127
bool cache
Definition: qfileinfo.h:128
unsigned uint
Definition: qglobal.h:351
void QFileInfo::slashify ( QString n)
staticprivate

Definition at line 58 of file qfileinfo_unix.cpp.

59 {
60  return;
61 }

Member Data Documentation

bool QFileInfo::cache
private

Definition at line 128 of file qfileinfo.h.

QFileInfoCache* QFileInfo::fic
private

Definition at line 127 of file qfileinfo.h.

QString QFileInfo::fn
private

Definition at line 126 of file qfileinfo.h.


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