All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Member Functions | Static Public Member Functions
Qtilities::Core::FileUtils Class Reference

The FileUtils class provides commonly used file related functionality. More...

#include <FileUtils.h>

Inheritance diagram for Qtilities::Core::FileUtils:
Inheritance graph
[legend]

List of all members.

Public Types

enum  ContainedTasks { TaskFindFilesUnderDir = 0 }
 Access names for tasks provided by FileUtils. More...

Public Member Functions

QFileInfoList findFilesUnderDir (const QString &dirName, const QString &file_filters=QString(), const QString &ignore_list=QString(), QDir::Filters filters=QDir::Files|QDir::NoDotAndDotDot, QDir::SortFlags sort=QDir::NoSort, bool first_run=true)
 Finds all files in the directory hierarhcy under a directory.
QFileInfoList lastFilesUnderDir ()
 Returns the last QFileInfoList produced by fileFilesUnderDir().
QObject * objectBase ()
 Returns the QObject* base of the interface.
const QObject * objectBase () const
 Returns a const QObject* base of the interface.
void setFindFilesUnderDirParams (const QString &dirName, const QString &file_filters=QString(), const QString &ignore_list=QString(), QDir::Filters filters=QDir::Files|QDir::NoDotAndDotDot, QDir::SortFlags sort=QDir::NoSort)
 Sets up the paramaters for future findFilesUnderDir() runs.
QString taskNameToString (ContainedTasks task_name) const
 ContainedTasks to string conversion function.
- Public Member Functions inherited from Qtilities::Core::Interfaces::ITaskContainer
void disableTask (int task_id)
 Disables the creation and registering in the global object pool of a task object to monitor the progress of the task.
void enableTask (int task_id)
 Enables the creation and registering in the global object pool of a task object to monitor the progress of the task.
int findTaskID (const QString &task_name) const
 Returns the task ID for the task specified by the given task_name.
bool isTaskActive (int task_id) const
 Checks if a specific task is active.
bool isTaskGlobal (int task_id) const
 Checks if a specific task is global or local. See Qtilities::Core::Interfaces::ITask::TaskType.
void setTaskGlobal (int task_id)
 Sets a task a global. See Qtilities::Core::Interfaces::ITask::TaskType.
void setTaskLocal (int task_id)
 Sets a task a local. See Qtilities::Core::Interfaces::ITask::TaskType.
ITasktask (int task_id) const
 Returns the task specified by the given task_id.
QList< ITask * > tasks () const
 A list of tasks provided by the object.
- Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase
QString objectOriginID () const
 Allows interfaces to provide some sort of source identification.
void setObjectOriginID (const QString &object_origin_id)
 Allows setting of the object source ID of this interface implementation.

Static Public Member Functions

static QString appendToFileName (const QString &fullFileName, const QString &append_string)
 Appends a string to the file name part of the file, that is after the file's name and before the extension.
static bool compareFiles (const QString &file1, const QString &file2)
 Compares two files and returns true if they are exactly the same, false otherwise.
static bool comparePaths (const QString &path1, const QString &path2, Qt::CaseSensitivity cs=Qt::CaseInsensitive)
 Compares two paths in a system independant way.
static int fileHashCode (const QString &file)
 Calculates a hash code for a text file.
static bool makeLocalCopyOfResource (const QString &resource_path, const QString &local_path, QString *errorMsg, QFile::Permissions local_permissions=QFile::ReadOwner|QFile::WriteOwner)
 Makes a local copy of the specified resource file.
static bool pathStartsWith (const QString &child_path, const QString &parent_path, Qt::CaseSensitivity cs=Qt::CaseInsensitive)
 Check if one path starts with another path (does it checks if the one path is a parent of another path).
static bool removeDir (const QString &dirName)
 Removes the specified directory along with all of its contents.
static QString removeFromFileName (const QString &fullFileName, int len)
 Removes the specified number of characters from the end of the file name part of the file, that is after the file's name and before the extension.
static QString toNativeSeparators (QString path)
 Converts a path to the native format of the underlying OS.

Additional Inherited Members

- Protected Member Functions inherited from Qtilities::Core::Interfaces::ITaskContainer
TaskfindTask (const QString &task_name) const
 Returns the Task object specified by the given task_name.
void registerTask (Task *task, const QString &task_name)
 Registers a task in this container.

Detailed Description

The FileUtils class provides commonly used file related functionality.

This class was added in Qtilities v1.0.


Member Enumeration Documentation

Access names for tasks provided by FileUtils.

Enumerator:
TaskFindFilesUnderDir 

The task which allows monitoring of the findFilesUnderDir() function's progress.


Member Function Documentation

bool FileUtils::comparePaths ( const QString &  path1,
const QString &  path2,
Qt::CaseSensitivity  cs = Qt::CaseInsensitive 
)
static

Compares two paths in a system independant way.

This function takes two paths and checks if they are the same. The function does the following:

  • If both paths exists, QFileInfo's == operator overload is used.

If both files does not exist, the following check is done:

  • Does a case insensitive check.
  • Removes any unwanted things in the path through QDir::cleanPath().
  • Does an environment independent check by converting both paths to the native characters of the OS on which this function is called.
Parameters:
path1The first path to check.
path2The second path to check against path1.
csThe case sensitivity of the check. This only applies to Windows. Only Unix based systems Qt::CaseSensitive is always used.
Returns:
True when the paths are the same, false otherwise.

This function was added in Qtilities v1.1.

int Qtilities::Core::FileUtils::fileHashCode ( const QString &  file)
static

Calculates a hash code for a text file.

If something went wrong (for example if the file does not exist), -1 is returned as an error code.

QFileInfoList Qtilities::Core::FileUtils::findFilesUnderDir ( const QString &  dirName,
const QString &  file_filters = QString(),
const QString &  ignore_list = QString(),
QDir::Filters  filters = QDir::Files | QDir::NoDotAndDotDot,
QDir::SortFlags  sort = QDir::NoSort,
bool  first_run = true 
)

Finds all files in the directory hierarhcy under a directory.

Finds all files under in the complete directory hierarhcy under dirName. The ITask implementation on this object is linked to this function's processing. Thus if you call this function, you can monitor the progress of findFilesUnderDir() through the ITask interface implementation provided by the TaskFindFilesUnderDir task.

FileUtils fu;
// All non-system and non-hidden files:
QFileInfoList files = fu.findFilesUnderDir("c:/my_path");

It is possible to find just directories by specifying the filters to be QDir::AllDirs without including QDir::Files.

Parameters:
dirNamePath of directory to search under.
file_filtersThe list of files which must be returned, when empty all files are returned. For example: *.bit *.log *.ngc, when empty all files added by default (*.*).
ignore_listFiles which should be ignored. Must be in the format: *.svn *.bak *.tmp
filtersThe QDir::Filters to apply when searching for files and folders.
sortThe QDir::SortFlags to apply when searching for files and folders.
first_runIgnore this parameter, used in recursive operations.
Returns:
A list of QFileInfos containing the information about found files.
bool FileUtils::makeLocalCopyOfResource ( const QString &  resource_path,
const QString &  local_path,
QString *  errorMsg,
QFile::Permissions  local_permissions = QFile::ReadOwner | QFile::WriteOwner 
)
static

Makes a local copy of the specified resource file.

This function will create a local copy of a resource file.

Parameters:
resource_pathThe resource to make a copy of.
local_pathThe target local path for the resource.
errorMsgWhen specified, will be populated by any error messages when the function returns false.
local_permissionsThe permissions to set on the local file after the copy process has been completed.

This function was added in Qtilities v1.3.

const QObject* Qtilities::Core::FileUtils::objectBase ( ) const
inlinevirtual

Returns a const QObject* base of the interface.

This function can be used in const methods, but make sure that you don't modify things that should stay const. An example where this is used is when we want to get a property on an object in a const method. This is a const operation.

Implements Qtilities::Core::Interfaces::IObjectBase.

bool FileUtils::pathStartsWith ( const QString &  child_path,
const QString &  parent_path,
Qt::CaseSensitivity  cs = Qt::CaseInsensitive 
)
static

Check if one path starts with another path (does it checks if the one path is a parent of another path).

Parameters:
child_pathThe child path.
parent_pathThe parent path.
csThe case sensitivity of the check. This only applies to Windows. Only Unix based systems Qt::CaseSensitive is always used.
Returns:
True when child_path starts with parent_path.

This function was added in Qtilities v1.2.

bool Qtilities::Core::FileUtils::removeDir ( const QString &  dirName)
static

Removes the specified directory along with all of its contents.

Parameters:
dirNamePath of directory to remove.
Returns:
true on success, false otherwise.
void Qtilities::Core::FileUtils::setFindFilesUnderDirParams ( const QString &  dirName,
const QString &  file_filters = QString(),
const QString &  ignore_list = QString(),
QDir::Filters  filters = QDir::Files | QDir::NoDotAndDotDot,
QDir::SortFlags  sort = QDir::NoSort 
)

Sets up the paramaters for future findFilesUnderDir() runs.

Parameters:
dirNamePath of directory to search under.
file_filtersThe list of files which must be returned, when empty all files are returned. For example: *.bit *.log *.ngc , when empty all files added by default (*.*).
ignore_listFiles which should be ignored. Must be in the format: *.svn *.bak *.tmp
filtersThe QDir::Filters to apply when searching for files and folders.
sortThe QDir::SortFlags to apply when searching for files and folders.
first_runIgnore this parameter, used in recursive operations.
QString FileUtils::toNativeSeparators ( QString  path)
static

Converts a path to the native format of the underlying OS.

This function is similar to QDir::toNativeSeparators(), but it supports linux as well.

This function was added in Qtilities v1.2.



Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé