KFileUtils

KFileUtils Namespace Reference

Functions

KCOREADDONS_EXPORT QStringList findAllUniqueFiles (const QStringList &dirs, const QStringList &nameFilters={})
 
KCOREADDONS_EXPORT QString makeSuggestedName (const QString &oldName)
 
KCOREADDONS_EXPORT QString suggestName (const QUrl &baseURL, const QString &oldName)
 

Detailed Description

A namespace for KFileUtils globals.

Function Documentation

◆ findAllUniqueFiles()

QStringList KFileUtils::findAllUniqueFiles ( const QStringList dirs,
const QStringList nameFilters = {} 
)

Locates all files matching the nameFilters in the given dirs The returned list does not contain duplicate file names.

In case there are multiple files the one which comes first in the dirs list is returned. For example:

Parameters
locationstandard location for the dir
dirdirectory in which the files are located
nameFiltersfilters that get passed to the QDirIterator that is used internally to iterate over the files in each dir in the list
Returns
list of absolute file paths
Since
5.85

Definition at line 73 of file kfileutils.cpp.

◆ makeSuggestedName()

QString KFileUtils::makeSuggestedName ( const QString oldName)

Given a string, "foo", representing a file/directory (which usually exists already), this function returns a suggested name for a file/directory in the form "foo (1)", "foo (2)" etc.

Unlike the suggestName() method, this function doesn't check if there is a file/directory with the newly suggested name; the idea being that this responsibility falls on the caller, e.g. one can use KIO::stat() to check asynchronously whether the new name already exists (in its parent directory) or not.

Since
5.76

Definition at line 19 of file kfileutils.cpp.

◆ suggestName()

QString KFileUtils::suggestName ( const QUrl baseURL,
const QString oldName 
)

Given a directory path and a string representing a file or directory (which usually exist already), this function returns a suggested name for a file/directory that doesn't exist in baseURL.

The suggested file name is of the form "foo (1)", "foo (2)" etc.

For local URLs, this function will check if there is already a file/directory with the new suggested name and will keep incrementing the number in the above format until it finds one that doesn't exist. Note that this function uses a blocking I/O call (using QFileInfo) to check the existence of the file/directory, this could be problematic for network mounts (e.g. SMB, NFS) as these are treated as local files by the upstream QFile code. An alternative is to use makeSuggestedName() and use KIO to stat the new file/directory in an asynchronous way.

Since
5.61

Definition at line 59 of file kfileutils.cpp.

KStandardDirs * dirs()
QStringList locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
KCOREADDONS_EXPORT QStringList findAllUniqueFiles(const QStringList &dirs, const QStringList &nameFilters={})
Locates all files matching the nameFilters in the given dirs The returned list does not contain dupli...
Definition: kfileutils.cpp:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:20:11 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.