Extending Qt Creator Manual | FileUtils

Extending Qt Creator Manual 4.6.1

# FileUtils Class

(Utils::FileUtils)

The FileUtils class contains file and directory related convenience functions. More...

Header: | #include <FileUtils>

- List of all members, including inherited members

## Static Public Members

FileName | canonicalPath(const FileName &path)
bool | copyRecursively(const FileName &srcFilePath, const FileName &tgtFilePath, QString *error = 0, const std::function<bool( QFileInfo, QFileInfo, QString * ) > &copyHelper = std::function<bool( QFileInfo, QFileInfo, QString * ) > ())
QString | fileSystemFriendlyName(const QString &name)
int | indexOfQmakeUnfriendly(const QString &name, int startpos = 0)
bool | isAbsolutePath(const QString &fileName)
bool | isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp)
bool | isRelativePath(const QString &fileName)
bool | makeWritable(const FileName &path)
QString | normalizePathName(const QString &name)
QString | qmakeFriendlyName(const QString &name)
bool | removeRecursively(const FileName &filePath, QString *error = 0)
QString | resolvePath(const QString &baseDir, const QString &fileName)
FileName | resolveSymlinks(const FileName &path)
QString | shortNativePath(const FileName &path)

## Detailed Description

The FileUtils class contains file and directory related convenience functions.

## Member Function Documentation

### `[static]` FileName FileUtils::canonicalPath(const FileName &path)

Recursively resolves possibly present symlinks in filePath. Unlike QFileInfo::canonicalFilePath(), this function will not return an empty string if path doesn't exist.

Returns the canonical path.

### `[static]` bool FileUtils::copyRecursively(const FileName &srcFilePath, const FileName &tgtFilePath, QString *error = 0, const std::function<bool( QFileInfo, QFileInfo, QString * ) > &copyHelper = std::function<bool( QFileInfo, QFileInfo, QString * ) > ())

Copies the directory specified by srcFilePath recursively to tgtFilePath. tgtFilePath will contain the target directory, which will be created. Example usage:

      QString error;
      book ok = Utils::FileUtils::copyRecursively("/foo/bar", "/foo/baz", &error);
      if (!ok)
        qDebug() << error;

This will copy the contents of /foo/bar into to the baz directory under /foo, which will be created in the process.

Note: The error parameter is optional.

Returns whether the operation succeeded.

### `[static]` QString FileUtils::fileSystemFriendlyName(const QString &name)

### `[static]` int FileUtils::indexOfQmakeUnfriendly(const QString &name, int startpos = 0)

### `[static]` bool FileUtils::isAbsolutePath(const QString &fileName)

### `[static]` bool FileUtils::isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp)

If filePath is a directory, the function will recursively check all files and return true if one of them is newer than timeStamp. If filePath is a single file, true will be returned if the file is newer than timeStamp.

Returns whether at least one file in filePath has a newer date than timeStamp.

### `[static]` bool FileUtils::isRelativePath(const QString &fileName)

### `[static]` bool FileUtils::makeWritable(const FileName &path)

### `[static]` QString FileUtils::normalizePathName(const QString &name)

### `[static]` QString FileUtils::qmakeFriendlyName(const QString &name)

### `[static]` bool FileUtils::removeRecursively(const FileName &filePath, QString *error = 0)

Removes the directory filePath and its subdirectories recursively.

Note: The error parameter is optional.

Returns whether the operation succeeded.

### `[static]` QString FileUtils::resolvePath(const QString &baseDir, const QString &fileName)

### `[static]` FileName FileUtils::resolveSymlinks(const FileName &path)

Recursively resolves symlinks if filePath is a symlink. To resolve symlinks anywhere in the path, see canonicalPath. Unlike QFileInfo::canonicalFilePath(), this function will still return the expected deepest target file even if the symlink is dangling.

Note: Maximum recursion depth == 16.

Returns the symlink target file path.

### `[static]` QString FileUtils::shortNativePath(const FileName &path)

Like QDir::toNativeSeparators(), but use prefix '~' instead of $HOME on unix systems when an absolute path is given.

Returns the possibly shortened path with native separators.