FileVisitor Class Reference

Visitor Pattern - visits files in a directory tree, recursively or non, performing the same operation on each file. More...

#include <filevisitor.h>

List of all members.

Public Slots

void processFileList (QStringList sl)
 Convenience method for processing a list of file specs.
void processEntry (QString pathname)
 processes a single directory entry Does not care if it is a directory or a file - does all the proper checking before calling the appropriate function, processFile() on files, or processDir() on directories.

Signals

void foundFile (QString filename)
 emitted whenever a file is found

Public Member Functions

 FileVisitor (QString nameFilter="*", bool recursive=true, bool symlinks=false)
 
Parameters:
nameFilter unix glob-style fileName filter e.g.

 FileVisitor (QStringList nameFilterList, bool recursive=true, bool symlinks=false)
void addNameFilter (QString nf)
 
Parameters:
nf a unix glob-style wildcard for specifying filename filters.

void setFilters (QStringList filters)
void setRecursive (bool r)
void clearFilter ()

Static Public Member Functions

static QStringList readLines (QFile &f)
 helper Function for reading all lines from a file in one line
static QStringList readLines (QString fn)
 helper function for reading all lines from a file in one line
static QString expandTilde (QString path)
 expands ~ only, not ~username.

Protected Member Functions

virtual void processFile (QString filename)
 override this to customize behavior
void processEntry (QFileInfo finfo)
 processEntry(QString) is a convenience function which calls this method.
void processDir (QString pathname)
 Process a directory - calls processFile on each file in the directory.
void processDir (QDir &directory)
 Process a directory - calls processFile on each file in the directory.
virtual bool skipDir (const QDir &dir)
 override this method if you want to skip particular directories.

Protected Attributes

QStringList m_filterList
bool m_Recursive
QDir::Filters m_DirFilter


Detailed Description

Visitor Pattern - visits files in a directory tree, recursively or non, performing the same operation on each file.

Author:
Alan Ezust sae@mcs.suffolk.edu
Version:
Id
filevisitor.h 1001 2009-03-16 21:52:17Z sae
Note: QDirIterator (Qt 4.3) serves a similar purpose and could be used instead of this class

Definition at line 17 of file filevisitor.h.


Constructor & Destructor Documentation

FileVisitor::FileVisitor ( QString  nameFilter = "*",
bool  recursive = true,
bool  symlinks = false 
)

Parameters:
nameFilter unix glob-style fileName filter e.g.

*.html

Parameters:
recursive if true, also process subdirectores
symlinks if true, also process symbolic links.

Definition at line 9 of file filevisitor.cpp.

References m_DirFilter, m_filterList, and m_Recursive.


Member Function Documentation

void FileVisitor::processFileList ( QStringList  sl  )  [slot]

Convenience method for processing a list of file specs.

Useful for handling command line arguments. Calls processEntry() on each file item in list.

Parameters:
sl - stringlist of files or directories to process

Definition at line 92 of file filevisitor.cpp.

References processEntry().

void FileVisitor::processEntry ( QString  pathname  )  [slot]

processes a single directory entry Does not care if it is a directory or a file - does all the proper checking before calling the appropriate function, processFile() on files, or processDir() on directories.

Parameters:
pathname location of a directory or a file

Definition at line 69 of file filevisitor.cpp.

References expandTilde().

Referenced by processDir(), and processFileList().

void FileVisitor::foundFile ( QString  filename  )  [signal]

emitted whenever a file is found

Parameters:
filename an absolute path

Definition at line 83 of file moc_filevisitor.cpp.

Referenced by processFile().

void FileVisitor::processFile ( QString  filename  )  [protected, virtual]

override this to customize behavior

The operation which is performed on each file (currently, it emits foundFile() on each found file).

Parameters:
filename (absolute or relative) path of file to be processed.

Definition at line 65 of file filevisitor.cpp.

References foundFile().

Referenced by processEntry().

bool FileVisitor::skipDir ( const QDir &  dir  )  [protected, virtual]

override this method if you want to skip particular directories.

Returns:
true if dir == (CVS | . | ..)

Definition at line 104 of file filevisitor.cpp.

Referenced by processEntry().

QString FileVisitor::expandTilde ( QString  path  )  [static]

expands ~ only, not ~username.

Parameters:
path a location that may contain a ~ prefix.
Returns:
an absolute path based on path.

Definition at line 56 of file filevisitor.cpp.

Referenced by processEntry().


The documentation for this class was generated from the following files:
Generated on Wed Sep 30 01:15:44 2009 for oopapidocs by  doxygen 1.5.1