Utils::FilePath Class
class Utils::FilePathFilePath クラスは、(リモートである可能性のある)ファイルシステム内のオブジェクトへのハンドルを抽象化したものであり、URL や、ローカルの場合にはファイルやディレクトリへのパスに類似しています。詳細...
| Header: | #include <FilePath> |
パブリック関数
| Utils::FilePath | absoluteFilePath() const |
| Utils::FilePath | absolutePath() const |
| Utils::FileStreamHandle | asyncCopy(const Utils::Continuation<> &cont, const Utils::FilePath &target) const |
| Utils::FileStreamHandle | asyncRead(const Utils::Continuation<QByteArray> &cont) const |
| Utils::FileStreamHandle | asyncWrite(const Utils::Continuation<qint64> &cont, const QByteArray &data) const |
| QString | baseName() const |
| qint64 | bytesAvailable() const |
| Utils::FilePath | canonicalPath() const |
| Utils::FilePath | chopped(int n) const |
| Utils::FilePath | cleanPath() const |
| void | clear() |
| QString | completeBaseName() const |
| QString | completeSuffix() const |
| bool | contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const |
| Utils::Result<> | copyFile(const Utils::FilePath &target) const |
| Utils::Result<> | copyRecursively(const Utils::FilePath &target) const |
| bool | createDir() const |
| Utils::Result<> | createSymLink(const Utils::FilePath &symLink) const |
| Utils::Result<Utils::FilePath> | createTempDir() const |
| Utils::Result<Utils::FilePath> | createTempFile() const |
| Utils::Environment | deviceEnvironment() const |
| Utils::Result<Utils::Environment> | deviceEnvironmentWithError() const |
| Utils::FilePaths | devicePathEnvironmentVariable() const |
| Utils::FilePaths | dirEntries(QDir::Filters filters) const |
| Utils::FilePaths | dirEntries(const Utils::FileFilter &filter, QDir::SortFlags sort = QDir::NoSort) const |
| QString | displayName(const QString &args = {}) const |
| bool | endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const |
| bool | ensureExistingFile() const |
| Utils::Result<> | ensureReachable(const Utils::FilePath &other) const |
| Utils::Result<> | ensureWritableDir() const |
| bool | equalsCaseSensitive(const Utils::FilePath &other) const |
| bool | exists() const |
| Utils::Result<QByteArray> | fileContents(qint64 maxSize = -1, qint64 offset = 0) const |
| QString | fileName() const |
| QStringView | fileNameView() const |
| QString | fileNameWithPathComponents(int pathComponents) const |
| qint64 | fileSize() const |
| QString | group() const |
| uint | groupId() const |
| bool | hasHardLinks() const |
| QStringView | host() const |
| Utils::FilePath | intern() const |
| bool | isAbsolutePath() const |
| bool | isChildOf(const Utils::FilePath &s) const |
| bool | isEmpty() const |
| bool | isExecutableFile() const |
| bool | isLocal() const |
| bool | isNewerThan(const QDateTime &timeStamp) const |
| bool | isRelativePath() const |
| bool | isResourceFile() const |
| bool | isRootPath() const |
| bool | isSameDevice(const Utils::FilePath &other) const |
| bool | isSameExecutable(const Utils::FilePath &other) const |
| bool | isSameFile(const Utils::FilePath &other) const |
| bool | isWritableDir() const |
| bool | isWritableFile() const |
| void | iterateDirectory(const Utils::FilePath::IterateDirCallback &callBack, const Utils::FileFilter &filter) const |
| QDateTime | lastModified() const |
| Utils::Result<Utils::FilePath> | localSource() const |
| Utils::Result<> | makeWritable() const |
| QString | nativePath() const |
| Utils::OsType | osType() const |
| QString | owner() const |
| uint | ownerId() const |
| Utils::FilePath | parentDir() const |
| QString | path() const |
| Utils::FilePath | pathAppended(const QString &path) const |
| QChar | pathComponentSeparator() const |
| QList<QStringView> | pathComponents() const |
| QChar | pathListSeparator() const |
| QStringView | pathView() const |
| QFileDevice::Permissions | permissions() const |
| std::optional<Utils::FilePath> | prefixRemoved(const QString &str) const |
| Utils::TextEncoding | processStdErrEncoding() const |
| Utils::TextEncoding | processStdOutEncoding() const |
| std::optional<Utils::FilePath> | refersToExecutableFile(Utils::FilePath::MatchScope matchScope) const |
| Utils::FilePath | relativeChildPath(const Utils::FilePath &parent) const |
| QString | relativeNativePathFromDir(const Utils::FilePath &anchorDir) const |
| QString | relativePathFromDir(const Utils::FilePath &anchorDir) const |
| Utils::Result<> | removeFile() const |
| Utils::Result<> | removeRecursively() const |
| Utils::Result<> | renameFile(const Utils::FilePath &target) const |
| Utils::FilePath | resolvePath(const QString &tail) const |
| Utils::FilePath | resolvePath(const Utils::FilePath &tail) const |
| Utils::FilePath | resolveSymlinks() const |
| QStringView | scheme() const |
| Utils::FilePaths | searchAllInDirectories(const Utils::FilePaths &dirs, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const |
| Utils::FilePaths | searchAllInPath() const |
| Utils::FilePaths | searchAllInPath(const Utils::FilePaths &additionalDirs, Utils::FilePath::PathAmending amending = AppendToPath, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const |
| void | searchHereAndInParents(const std::function<IterationPolicy (const FilePath &)> &constraint) const |
| Utils::FilePath | searchHereAndInParents(const QString &fileName, QDir::Filter type) const |
| Utils::FilePath | searchHereAndInParents(const QStringList &fileNames, QDir::Filter type) const |
| Utils::FilePath | searchInDirectories(const Utils::FilePaths &dirs, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const |
| Utils::FilePath | searchInPath() const |
| Utils::FilePath | searchInPath(const Utils::FilePaths &additionalDirs, Utils::FilePath::PathAmending amending = AppendToPath, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const |
| void | setParts(const QStringView scheme, const QStringView host, const QStringView path) |
| Utils::Result<> | setPermissions(QFileDevice::Permissions permissions) const |
| QString | shortNativePath() const |
| bool | startsWithDriveLetter() const |
| Utils::FilePath | stringAppended(const QString &str) const |
| QString | suffix() const |
| QStringView | suffixView() const |
| Utils::FilePath | symLinkTarget() const |
| std::optional<Utils::FilePath> | tailRemoved(const QString &str) const |
| Utils::Result<Utils::FilePath> | tmpDir() const |
| QString | toFSPathString() const |
| QFileInfo | toFileInfo() const |
| QVariant | toSettings() const |
| QUrl | toUrl() const |
| QString | toUrlishString() const |
| QString | toUserOutput() const |
| QVariant | toVariant() const |
| Utils::FilePath | withExecutableSuffix() const |
| Utils::FilePath | withNewMappedPath(const Utils::FilePath &newPath) const |
| Utils::FilePath | withNewPath(const QString &newPath) const |
| Utils::FilePath | withSuffix(const QString &suffix) const |
| QString | withTildeHomePath() const |
| Utils::Result<qint64> | writeFileContents(const QByteArray &data) const |
| Utils::FilePath | operator/(const QString &str) const |
| Utils::FilePath & | operator/=(const QString &str) |
静的パブリックメンバー
| Utils::FilePath | currentWorkingPath() |
| Utils::FilePath | fromFileInfo(const QFileInfo &info) |
| Utils::FilePath | fromParts(const QStringView scheme, const QStringView host, const QStringView path) |
| Utils::FilePath | fromPathComponents(const QList<QStringView> &components) |
| Utils::FilePath | fromPathPart(const QStringView path) |
| Utils::FilePath | fromSettings(const QVariant &variant) |
| Utils::FilePath | fromString(const QString &filepath) |
| Utils::FilePath | fromStringWithExtension(const QString &filepath, const QString &defaultExtension) |
| Utils::FilePath | fromUrl(const QUrl &url) |
| Utils::FilePath | fromUserInput(const QString &filePath) |
| Utils::FilePath | fromUtf8(const char *filename, int filenameSize = -1) |
| Utils::FilePath | fromVariant(const QVariant &variant) |
| void | iterateDirectories(const Utils::FilePaths &dirs, const Utils::FilePath::IterateDirCallback &callBack, const Utils::FileFilter &filter) |
| void | removeDuplicates(Utils::FilePaths &files) |
| void | sort(Utils::FilePaths &files) |
| std::vector<Utils::Result<std::unique_ptr<Utils::FilePathWatcher>>> | watch(const Utils::FilePaths &paths) |
詳細な説明
理想的には、Qt Creator のコードではすべてこの目的のために FilePath を使用すべきですが、歴史的な理由により、依然としてQString を使用している部分が多数存在します。
ファイルパスは、内部的には3つの文字列の組として格納されます。1つ目の部分(「スキーム」)はアクセス方法を、2つ目の部分(「ホスト」)はファイルシステム(例:ホスト)を、3つ目の部分(「パス」)はシステム上の(潜在的な)オブジェクトを識別します。
FilePathは、「すべてはファイルである」というUnixのパラダイムに従っています。つまり、通常のファイルやディレクトリを指すFilePathの間には、概念上の違いはありません。
FilePath は、そのホスト部分を通じて、暗黙的にオペレーティングシステムに関連付けられています。FilePath のパス部分は、関連付けられた OS に関係なく、内部的にはスラッシュ(/)を使用して保存されます。
Windows(および、設定で別段の指定がない限り macOS)に関連付けられた FilePath のパス部分は、大文字と小文字を区別せずに互いに比較されます。 同一のファイルに対して複数の FilePath 表現が存在する可能性があるため(たとえば、異なるアクセス方法によって同じファイルにアクセスできる場合など)、等価性の比較には一般的に外部情報が必要となる点に注意してください。
FilePathと他の文字列のような表現の間には、いくつかの変換があります:
- FilePath::fromUserInput()
Qt Creator 以外のソース(例:GUI コントロールへのユーザー入力、環境変数、コマンドライン引数など)からの文字列のようなデータを、Qt Creator に変換します。
入力にはスラッシュとバックスラッシュの両方が含まれていてもよく、それらは解析され正規化されます。
- FilePath::nativePath()
FilePath を、関連する OS のスラッシュ表記に変換し、スキーム部分とホスト部分を削除します。
これは、関連する OS の機能と連携する際に役立ちます。例えば、この FilePath を、関連する OS 上で実行されるコマンドの引数として渡す場合などです。
注: CommandLine に実行可能ファイルとして渡される FilePathは 、通常、ユーザーコードによって変更されることはありません。Process はこれを使用してリモートシステムを特定し、必要な変換を内部的に行います。
- FilePath::toFSPathString()
FilePath を [drive:]/__qtc_devices__/scheme/host/path という形式の文字列に変換します。
この変換結果は、ほとんどの場合、リモート環境やQDir/QFileInfo でも機能しますが、FilePathを直接使用する場合よりも処理速度が遅くなります。したがって、FilePathへの適切な移植が困難であるか、不可能な場合(例えば、FilePathを使用しない外部のQtベースのライブラリを使用している場合など)にのみ使用してください。
- FilePath::toUserOutput()
FilePathを、関連するOSのスラッシュ表記に変換し、スキームとホストの部分は保持します。
この形式を利用するアプリケーションは事実上存在しないため、リモートパスに対してこれが役立つことはほとんどありません。
- FilePath::displayName()
FilePath を関連する OS のスラッシュ表記に変換し、スキームとホストを「 on <device>」という接尾辞として追加します。
これは、GUI におけるユーザー向けの静的な出力に役立ちます。
- FilePath::fromVariant(),FilePath::toVariant()
これらは、QVariant ベースの API(設定やアイテムモデル(内部)データなど)との連携に使用されます。
- FilePath::toUrlishString()
FilePath を scheme://host/path という形式の文字列に変換します。
主にレガシーコードやデバッグの目的で使用されます。
ほとんどの場合、上記のより専門的な変換のいずれかを使用する方が適切です。
文字列のようなデータの変換は、常にQt Creator コードの最外層で行い、インバウンド通信にはfromUserInput() を使用し、アウトバウンド通信には媒体に応じてnativePath() またはdisplayName() を使用する必要があります。
QVariant ベースの Qt API との通信には、fromVariant() およびtoVariant() を使用する必要があります。
toUrlishString() の使用は、QString ベースのファイルパスを FilePath に変換することで段階的に廃止する必要があります。ただし、後でpathAppended() などで使用される FilePath のパス断片については例外であり、これらはQString の形式のまま維持する必要があります。
UNCパスは「//」で始まる形式を維持し、この特徴によって識別可能です。
メンバー関数のドキュメント
Utils::FilePath FilePath::absoluteFilePath() const
このパスの絶対パスを返し、「.」および「..」の要素を解決します。
このパスがすでに絶対パスである場合は、不要な要素を削除してそのまま返します。このパスが相対パスである場合は、現在の作業ディレクトリを基準に解決します。
absolutePath() およびcleanPath()も参照してください 。
Utils::FilePath FilePath::absolutePath() const
このパスの親ディレクトリの絶対パスを返します。
これが相対パスである場合、まず現在の作業ディレクトリを基準に解決されます。
absoluteFilePath() およびparentDir()も参照してください 。
Utils::FileStreamHandle FilePath::asyncCopy(const Utils::Continuation<> &cont, const Utils::FilePath &target) const
このファイルをtarget に非同期でコピーし、完了時にcont を呼び出します。
操作をキャンセルするために使用できるハンドルを返します。
asyncRead() およびasyncWrite()も参照してください 。
Utils::FileStreamHandle FilePath::asyncRead(const Utils::Continuation<QByteArray> &cont) const
このファイルを非同期で読み込み、処理完了時にファイルの内容を引数としてcont を呼び出します。
操作をキャンセルするために使用できるハンドルを返します。
asyncWrite() およびasyncCopy()も参照してください 。
Utils::FileStreamHandle FilePath::asyncWrite(const Utils::Continuation<qint64> &cont, const QByteArray &data) const
data をこのファイルに非同期で書き込み、完了時に書き込みバイト数を引数としてcont を呼び出します。
操作をキャンセルするために使用できるハンドルを返します。
asyncRead() およびasyncCopy()も参照してください 。
QString FilePath::baseName() const
パスを除いたファイルのベース名を返します。
ベース名は、ファイル名の先頭から最初の「.」文字(この文字自体は含まない)までのすべての文字で構成されます。
qint64 FilePath::bytesAvailable() const
このパスが指すファイルシステム上で利用可能なバイト数を返します。情報を特定できない場合は 0 を返します。
Utils::FilePath FilePath::canonicalPath() const
このファイル名に含まれる可能性のあるシンボリックリンクを再帰的に解決します。
Windowsでは、SUBSTおよび再マウントされたNTFSドライブも解決します。QFileInfo::canonicalFilePath()とは異なり、この関数はpathが存在しない場合でも空文字列を返しません。
正規化されたパスを返します。
Utils::FilePath FilePath::chopped(int n) const
ローカルパスの「n 」という文字列を除去したパスを返します。使用例:
backup = FilePath("/tmp/example.txt.backup"); real = backup.chopped(7); assert(real == FilePath("/tmp/example.txt"))
Utils::FilePath FilePath::cleanPath() const
QDir::cleanPath() と同様に、パス部分をクリーンアップします。
- ディレクトリ区切り文字を正規化(つまり、プラットフォーム固有の区切り文字を「/」に変換)し、余分な区切り文字を削除し、「.」や「..」を(可能な限り)展開します。
- シンボリックリンクは保持されます。この関数は正規化されたパスを返すのではなく、入力に対する最も単純なバージョンを返します。 たとえば、「./local」は「local」に、「local/../bin」は「bin」に、「/local/usr/../bin」は「/local/bin」になります。
void FilePath::clear()
このFilePath を空の状態にリセットし、スキーム、ホスト、およびパスをクリアします。
QString FilePath::completeBaseName() const
パスを除いたファイルの完全なベース名を返します。
完全なベース名は、最後の「.」文字(これを除く)までのファイル名に含まれるすべての文字で構成されます。「.ui.qml」の場合、これらは1つの拡張子として扱われます。
QString FilePath::completeSuffix() const
ファイルの完全なサフィックス(拡張子)を返します。
完全な拡張子は、ファイル名内の最初の「.」以降(ただし、その「.」自体は含まない)のすべての文字で構成されます。
bool FilePath::contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const
path() にs が含まれているかどうかを返します。
Utils::Result<> FilePath::copyFile(const Utils::FilePath &target) const
このファイルをtarget にコピーします。
デバイス間のコピー(つまり、異なるスキーム/ホストの組み合わせ間)は、すべてのコンテンツを読み取り、それを宛先に書き込むことで処理されます。成功した場合はResult<> を返し、失敗した場合はエラー結果を返します。
copyRecursively() およびrenameFile()も参照してください 。
Utils::Result<> FilePath::copyRecursively(const Utils::FilePath &target) const
このパスにあるディレクトリまたはファイルを、target に再帰的にコピーします。
成功した場合は有効なResult<> を返し、失敗した場合はエラー結果を返します。
copyFile() およびrenameFile()も参照してください 。
bool FilePath::createDir() const
この場所にディレクトリを作成します。
ディレクトリの作成に成功した場合はtrueを、失敗した場合はfalseを返します。事前にディレクトリが存在していた場合でも同様です。
ensureWritableDir()も参照してください 。
Utils::Result<> FilePath::createSymLink(const Utils::FilePath &symLink) const
このファイルパスを指すシンボリックリンク「symLink 」を作成します。
注: Windowsでは 、管理者権限を持っているか、開発者モードが有効になっていない限り、この関数は動作しません。
Utils::Result<Utils::FilePath> FilePath::createTempDir() const
このパスをテンプレートとして、新しい一時ディレクトリを作成します。
成功した場合は作成された一時ディレクトリのパスを返し、失敗した場合はエラー結果を返します。不要になった際のディレクトリの削除は、呼び出し側の責任となります。
Utils::Result<Utils::FilePath> FilePath::createTempFile() const
このパスをテンプレートとして、新しい一時ファイルを作成します。
成功した場合は作成された一時ファイルのパスを返し、失敗した場合はエラー結果を返します。ファイルが不要になった際の削除は、呼び出し元が責任を持って行う必要があります。
[static] Utils::FilePath FilePath::currentWorkingPath()
現在の作業ディレクトリをFilePath として返します。
Utils::Environment FilePath::deviceEnvironment() const
このパスが属するデバイスの環境を返します。
ローカルパスの場合、これはシステム環境となります。リモートパスの場合、デバイスの環境が照会されます。失敗した場合はアサートを行い、空の環境を返します。
deviceEnvironmentWithError()も参照してください 。
Utils::Result<Utils::Environment> FilePath::deviceEnvironmentWithError() const
このパスが属するデバイスの環境を返します。失敗した場合はエラー結果を返します。
deviceEnvironment()も参照してください 。
Utils::FilePaths FilePath::devicePathEnvironmentVariable() const
このパスが属するデバイスのPATHディレクトリを、各エントリにこのパスのスキームとホストを適用した形で返します。
Utils::FilePaths FilePath::dirEntries(QDir::Filters filters) const
filters に一致するディレクトリのエントリを返します。
iterateDirectory()も参照してください 。
Utils::FilePaths FilePath::dirEntries(const Utils::FileFilter &filter, QDir::SortFlags sort = QDir::NoSort) const
filter に一致するディレクトリのエントリを返します。オプションで、sort に基づいてソートすることもできます。
iterateDirectory()も参照してください 。
QString FilePath::displayName(const QString &args = {}) const
ファイルパスを、関連するOSのスラッシュ表記に変換し、スキームとホストを「 on <device>」というサフィックスとして追加します。
これは、GUI におけるユーザー向けの静的な出力に役立ちます。
args が空でない場合、ファイルパスの後に出力に追加されます:「<path> <args> on <device>」。
bool FilePath::endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const
path() がs で終わっているかどうかを返します。
bool FilePath::ensureExistingFile() const
このパスにファイルが存在しない場合、そのパスにファイルを作成します。
ファイルが存在するか、正常に作成された場合はtrue を返し、それ以外の場合はfalse を返します。
Utils::Result<> FilePath::ensureReachable(const Utils::FilePath &other) const
このデバイスからother にアクセスできることを確認します。
ローカルパスの場合、other もローカルである場合にのみ成功します。リモートパスの場合、必要な接続を設定するためにデバイスフックが呼び出されます。
other にアクセス可能な場合は正常なResult<> を返し、そうでない場合はエラー結果を返します。
Utils::Result<> FilePath::ensureWritableDir() const
この場所にあるディレクトリを再利用するか、新しいディレクトリを作成します。
ディレクトリが存在し、その後書き込み可能であれば、成功を示すResult<> を返します。そうでない場合は、ディレクトリの作成やアクセスができなかった理由を説明するエラー結果を返します。
createDir()も参照してください 。
bool FilePath::equalsCaseSensitive(const Utils::FilePath &other) const
このファイルパスが、大文字小文字を区別してother と等しい場合、true を返します。これは、NTFS を使用する Windows のような、半大文字小文字区別のあるシステムで関連します。
QTCREATORBUG-30846も参照してください 。
bool FilePath::exists() const
このFilePath を持つファイルまたはディレクトリが存在するかどうかを示すbool値を返します。
Utils::Result<QByteArray> FilePath::fileContents(qint64 maxSize = -1, qint64 offset = 0) const
ファイルの内容を読み取り、返します。
maxSize が-1でない場合、最大maxSize バイトが読み込まれます。読み取りはバイト位置offset から開始されます。
ファイルを読み込めなかった場合は、エラー結果を返します。
writeFileContents()も参照してください 。
QString FilePath::fileName() const
最後のパス構成要素(ファイル名)を、ディレクトリパスを含まないQString として返します。
fileNameView()、baseName()、およびsuffix()も参照してください 。
QStringView FilePath::fileNameView() const
ディレクトリパスを一切含めず、最後のパス構成要素(ファイル名)をQStringView として返します。
fileName()も参照してください 。
QString FilePath::fileNameWithPathComponents(int pathComponents) const
pathComponents で指定された先頭のディレクトリ構成要素を含んだファイル名を返します。
- pathComponents が 0 の場合、ファイル名のみが返されます。
- pathComponents が -1 の場合、完全なパスが返されます。
- パス構成要素の数がpathComponents より少ない場合は、URL のような完全な文字列が返されます。
qint64 FilePath::fileSize() const
ファイルのサイズをバイト単位で返します。サイズを特定できない場合は 0 を返します。
[static] Utils::FilePath FilePath::fromFileInfo(const QFileInfo &info)
info からFilePath を生成します。
[static] Utils::FilePath FilePath::fromParts(const QStringView scheme, const QStringView host, const QStringView path)
scheme 、host 、path の各部分から、FilePath を構築します。
scheme()、host()、およびpath()も参照してください 。
[static] Utils::FilePath FilePath::fromPathComponents(const QList<QStringView> &components)
指定されたパス `components ` を '/' で連結して、ローカルの `FilePath ` を生成します。
components が空の場合、空のFilePath が返されます。最初の要素が '/' の場合、結果のパスは絶対パスになります。
pathComponents()も参照してください 。
[static] Utils::FilePath FilePath::fromPathPart(const QStringView path)
パス部分のみをpath に設定したローカルな `FilePath ` を生成します。スキーム部分とホスト部分は空のままにします。
[static] Utils::FilePath FilePath::fromSettings(const QVariant &variant)
toSettings() に保存されているQVariant variant から、FilePath を生成します。
toSettings() およびfromVariant()も参照してください 。
[static] Utils::FilePath FilePath::fromString(const QString &filepath)
FilePath をfilepath
filepath の有効性はチェックされません。以下の形式で指定できます:
- /some/absolute/local/path
- some/relative/path
- scheme://host/absolute/path
- scheme://host/./relative/path
注: ./は パスの一部としてそのまま扱われます
filepath を解析する際、一部のデコードが行われます。ホスト部分に %25 の文字列が含まれている場合、ホスト名では % に置き換えられ、ホスト部分に %2f の文字列が含まれている場合、ホスト名では / に置き換えられます。
パス部分は、プラットフォームやファイルシステムに関係なく、/ で区切られた複数の部分で構成される場合があります。
パス区切り文字としてバックスラッシュが含まれる可能性のある文字列からFilePath オブジェクトを作成するには、fromUserInput を使用してください。
toFSPathString 、toUserOutput 、およびfromUserInputも参照してください 。
[static] Utils::FilePath FilePath::fromStringWithExtension(const QString &filepath, const QString &defaultExtension)
filepath から `FilePath ` を生成します。filepath に拡張子がまだない場合、defaultExtension が末尾に追加されます。
filepath 有効性についてはチェックされません。
[static] Utils::FilePath FilePath::fromUrl(const QUrl &url)
url から `FilePath ` を生成します。
toUrl()も参照してください 。
[static] Utils::FilePath FilePath::fromUserInput(const QString &filePath)
FilePath を以下から構築しますfilePath
パス `filePath ` がクリーンアップされ、`~` がホームパスに置き換えられます。
[static] Utils::FilePath FilePath::fromUtf8(const char *filename, int filenameSize = -1)
filename から、filenameSize を用いて、UTF-8 でエンコードされたFilePath を構築します。
filename 有効性はチェックされません。
[static] Utils::FilePath FilePath::fromVariant(const QVariant &variant)
variant からFilePath を生成します。
toVariant()も参照してください 。
QString FilePath::group() const
このファイルの所有者グループ名を返します。情報が利用できない場合は、空の文字列を返します。
groupId() およびowner()も参照してください 。
uint FilePath::groupId() const
このファイルの所有者であるグループの数値グループIDを返します。取得できない場合は0を返します。
group() およびownerId()も参照してください 。
bool FilePath::hasHardLinks() const
このパスにあるファイルにハードリンクが複数存在する場合、true を返します。
QStringView FilePath::host() const
FilePath のホスト部分を返し、リモートファイルシステムを識別します。
ローカルパスに対しては、空のQStringView を返します。
scheme()、path()、およびfromParts()も参照してください 。
Utils::FilePath FilePath::intern() const
インターン化されたデータを含むコピーを返します。
bool FilePath::isAbsolutePath() const
パスが絶対パスであるかどうかを確認します。
パスがスラッシュ、または文字とコロン、あるいはコロンとスラッシュで始まる場合、true を返します。
注:これは Qt Creator が現在実行されているプラットフォームとは無関係であるため、必ずしもそのプラットフォームにおける絶対パスの定義と一致するとは限りません。使用には注意し、できれば使用を避けてください。
isRelativePath()も参照してください 。
bool FilePath::isChildOf(const Utils::FilePath &s) const
FilePath がs の子要素であるかどうかを返します。
bool FilePath::isEmpty() const
パス部分が空の場合、true を返します。スキームとホストは考慮されません。
bool FilePath::isExecutableFile() const
これが実行可能ファイルであるかどうかを示すブール値を返します。
bool FilePath::isLocal() const
このパスがローカルファイルシステムを指している場合(スキームがないか、スキームが「file」である場合)、true を返します。
bool FilePath::isNewerThan(const QDateTime &timeStamp) const
このファイルまたはディレクトリが `timeStamp` よりも新しい場合、true を返します。
ディレクトリの場合、チェックは含まれるすべてのファイルに対して再帰的に行われ、いずれかのファイルがtimeStamp より新しい場合はtrue を返します。
bool FilePath::isRelativePath() const
パスが相対パスであるかどうかを確認します。
パスがスラッシュ、文字とコロン、またはコロンとスラッシュのいずれでも始まっていない場合、trueを返します。
注:これは 、Qt Creator が現在実行されているプラットフォームとは無関係であるため、必ずしもそのプラットフォームにおける相対パスの定義と一致するとは限りません。使用には注意し、極力避けるようにしてください。
isAbsolutePath()も参照してください 。
bool FilePath::isResourceFile() const
このパスが Qt リソースファイルを指している場合、つまり「qrc」スキーマを持つか、パスの先頭が「:」で始まる場合、true を返します。
bool FilePath::isRootPath() const
このパスがファイルシステムのルート(たとえば、Unix の「/」や Windows の「C:/」など)である場合、true を返します。
bool FilePath::isSameDevice(const Utils::FilePath &other) const
other がこのパスと同じデバイス(スキームおよびホスト)を指している場合、true を返します。
bool FilePath::isSameExecutable(const Utils::FilePath &other) const
other が、".exe" や ".bat" といったプラットフォーム固有の拡張子を含めて、このパスと同じ実行ファイルを指している場合、true を返します。
isSameFile()も参照してください 。
bool FilePath::isSameFile(const Utils::FilePath &other) const
other がこのパスと同じファイルを指している場合、true を返します。
2つのパスは、文字列として等しくなくても、同じファイルを指している場合があります。例えば、シンボリックリンクや異なるアクセス方式が使用されている場合などです。この関数は、パスが異なる場合、比較にデバイスのファイルIDを使用します。
isSameExecutable() およびisSameDevice()も参照してください 。
bool FilePath::isWritableDir() const
これが書き込み可能なディレクトリであるかどうかを示すブール値を返します。
bool FilePath::isWritableFile() const
このファイルが書き込み可能かどうかを示すブール値を返します。
[static] void FilePath::iterateDirectories(const Utils::FilePaths &dirs, const Utils::FilePath::IterateDirCallback &callBack, const Utils::FileFilter &filter)
dirs の各ディレクトリ内で、filter に一致する各ディレクトリエントリに対して、callBack を実行します。
iterateDirectory()も参照してください 。
void FilePath::iterateDirectory(const Utils::FilePath::IterateDirCallback &callBack, const Utils::FileFilter &filter) const
filter に一致する各ディレクトリエントリに対して、callBack を実行します。
QDateTime FilePath::lastModified() const
このファイルまたはディレクトリが最後に変更された日時を返します。
変更時刻を特定できない場合は、無効なQDateTime を返します。
Utils::Result<Utils::FilePath> FilePath::localSource() const
ローカルファイルシステムからアクセス可能な同じファイルを表すFilePath を返します。そのようなマッピングが存在しない場合は、エラー結果を返します。
ローカルパスの場合は、*this を返します。リモートパスの場合は、デバイスフックを参照します。
Utils::Result<> FilePath::makeWritable() const
このファイルの所有者に書き込み権限を追加します。
成功した場合はResult<> を返し、失敗した場合はエラー結果を返します。
setPermissions() およびpermissions()も参照してください 。
QString FilePath::nativePath() const
ターゲットシステムのネイティブコマンドに渡すための、デバイスプレフィックスを含まないQString を返します。
区切り文字を、このパスが属するシステムのネイティブ形式に変換します。
Utils::OsType FilePath::osType() const
このパスが属するデバイスのOSの種類を返します。
ローカルパスの場合は、ホストのOSの種類を返します。リモートパスの場合は、デバイスのOSの種類を照会します。
QString FilePath::owner() const
このファイルの所有者の名前を返します。情報が利用できない場合は、空の文字列を返します。
ownerId() およびgroup()も参照してください 。
uint FilePath::ownerId() const
このファイルの所有者の数値ユーザーIDを返します。取得できない場合は0を返します。
owner() およびgroupId()も参照してください 。
Utils::FilePath FilePath::parentDir() const
ファイルパスの親ディレクトリを検索します。
ファイルパスがすでにルートレベルのディレクトリである場合は、空のファイルパスを返します。
最後のセグメントが削除されたファイルパスを返します。
QString FilePath::path() const
FilePath のパス部分を、スラッシュ(/)を使用してQString として返します。
pathView()、scheme()、およびhost()も参照してください 。
Utils::FilePath FilePath::pathAppended(const QString &path) const
このパスに「path 」を「/」で連結して返します。
path 内のバックスラッシュは、スラッシュに正規化されます。これはoperator/(path) と同等です。
stringAppended() およびoperator/()も参照してください 。
QChar FilePath::pathComponentSeparator() const
このパスのパス構成要素の区切り文字を返します。
パスの区切り文字を返します。
QList<QStringView> FilePath::pathComponents() const
「/」を区切りとして、パスを構成要素ごとに分割して返します。
Windows のパスでは、ドライブ文字(例: "C:")とルートスラッシュが、先頭の構成要素として個別に返されます。
先頭の '/' は、単一の '/' 構成要素として返されます。
fromPathComponents()も参照してください 。
QChar FilePath::pathListSeparator() const
このパスのOSに対応するPATHリストの区切り文字を返します。Windowsでは「;」、それ以外のOSでは「:」です。
QStringView FilePath::pathView() const
FilePath のパス部分を、スラッシュ(/)を使用してQStringView の形式で返します。
path()、scheme()、およびhost()も参照してください 。
QFileDevice::Permissions FilePath::permissions() const
このファイルまたはディレクトリの権限を返します。
権限を判別できない場合は、空の権限セットを返します。
setPermissions() およびmakeWritable()も参照してください 。
std::optional<Utils::FilePath> FilePath::prefixRemoved(const QString &str) const
パス部分の先頭から「str 」を削除したパスを返します。ただし、パスが「str 」で始まらない場合は、「std::nullopt 」を返します。
Utils::TextEncoding FilePath::processStdErrEncoding() const
そのデバイス上のプロセスが標準エラー出力に使用するテキストエンコーディングを返します。
Utils::TextEncoding FilePath::processStdOutEncoding() const
そのデバイス上のプロセスが標準出力に使用するテキストエンコーディングを返します。
std::optional<Utils::FilePath> FilePath::refersToExecutableFile(Utils::FilePath::MatchScope matchScope) const
このFilePath のネイティブパスを持つプロセスが起動する可能性が高いかどうかを示すブール値を返します。
これは、一般的には `isExecutableFile()` と同等です。Windows では、`matchScope` の設定に応じて、さまざまなサフィックスが追加される場合があります。
Utils::FilePath FilePath::relativeChildPath(const Utils::FilePath &parent) const
parent からの相対パスを返します。
`this`が`parent`の子要素でない場合、空の`FilePath `を返します。結果は決して「../」で始まることはありません。`this`が`parent`の下にない場合は、代わりに`relativePathFromDir() `を使用してください。
relativePathFromDir() およびisChildOf()も参照してください 。
QString FilePath::relativeNativePathFromDir(const Utils::FilePath &anchorDir) const
anchorDir から現在位置までの相対パスを、関連する OS のネイティブなパス区切り文字を使用して返します。
使用例:
FilePath filePath("C:/foo/b/ar/file.txt"); QString relativePath=filePath.relativePathFromDir(FilePath("C:\\foo\\c")); qDebug() << relativePath;
デバッグ出力は「"..\b\ar\file.txt" 」となります。
relativePathFromDir()も参照してください 。
QString FilePath::relativePathFromDir(const Utils::FilePath &anchorDir) const
ディレクトリ `anchorDir` からの `FilePath ` の相対パスを返します。`FilePath ` およびアンカーディレクトリは、ファイルまたはディレクトリのいずれでもかまいません。
使用例:
FilePath filePath("/foo/b/ar/file.txt"); QString relativePath=filePath.relativePathFromDir(FilePath("/foo/c")); qDebug() << relativePath;
デバッグ出力は「"../b/ar/file.txt" 」となります。
relativeNativePathFromDir()も参照してください 。
[static] void FilePath::removeDuplicates(Utils::FilePaths &files)
files から重複エントリをその場で削除し、順序は維持します。
Utils::Result<> FilePath::removeFile() const
このパスにあるファイルを削除します。
成功した場合はResult<> を、失敗した場合はエラー結果を返します。
removeRecursively()も参照してください 。
Utils::Result<> FilePath::removeRecursively() const
この filePath が指すディレクトリとそのサブディレクトリを再帰的に削除します。
Utils::Result<> FilePath::renameFile(const Utils::FilePath &target) const
このファイルをtarget に移動(名前変更)します。
target が同じデバイス上にある場合は、ネイティブのファイル名変更が使用されます。そうでない場合は、ファイルがコピーされ、元のファイルは削除されます。成功した場合は成功を示す `Result<> ` を返し、失敗した場合はエラー結果を返します。
copyFile() およびremoveFile()も参照してください 。
Utils::FilePath FilePath::resolvePath(const QString &tail) const
tail が相対パスである場合は、これにtail を追加し、絶対パスである場合は、パス部分のみをtail に置き換えます(このパスのスキーマとホストは保持されます)。
Utils::FilePath FilePath::resolvePath(const Utils::FilePath &tail) const
tailが相対パスである場合、これにtail を追加します。
tail が絶対パスである場合は tail を返し、そうでない場合は this + tail を返します。
Utils::FilePath FilePath::resolveSymlinks() const
これがシンボリックリンクの場合、シンボリックリンクを再帰的に解決します。
パス内の任意の場所にあるシンボリックリンクを解決するには、canonicalPath を参照してください。QFileInfo::canonicalFilePath() とは異なり、この関数は、シンボリックリンクがダングリングリンクであっても、期待される最深部のターゲットファイルを返します。
注: 再帰の最大 深さは 16 です。
シンボリックリンクのターゲットファイルのパスを返します。
QStringView FilePath::scheme() const
FilePath のスキーム部分(「docker」や「ssh」など)を返します。
ローカルパスについては、空のQStringView を返します。
host()、path()、およびfromParts()も参照してください 。
Utils::FilePaths FilePath::searchAllInDirectories(const Utils::FilePaths &dirs, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const
dirs のいずれかに存在する、このファイル名に一致するすべての実行可能ファイルを返します。必要に応じてfilter によるフィルタリングを行い、実行可能ファイルの拡張子の処理はmatchScope で制御されます。
searchInDirectories() およびsearchAllInPath()も参照してください 。
Utils::FilePaths FilePath::searchAllInPath() const
関連するデバイスの PATH 内に、この名前の実行可能ファイルをすべて検索します。
Utils::FilePaths FilePath::searchAllInPath(const Utils::FilePaths &additionalDirs, Utils::FilePath::PathAmending amending = AppendToPath, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const
amending に従って、additionalDirs を追加した状態で、関連付けられたデバイスの PATH 内にあるこの名前のすべての実行可能ファイルを検索します。オプションで、filter を使用して結果をフィルタリングし、matchScope に従って拡張子を処理します。
searchInPath() およびsearchAllInDirectories()も参照してください 。
void FilePath::searchHereAndInParents(const std::function<IterationPolicy (const FilePath &)> &constraint) const
このディレクトリとその親ディレクトリを順に探索し、それぞれに対してconstraint を呼び出します。
constraint が `IterationPolicy::Stop ` を返した場合、またはルートに到達した時点で反復処理が停止します。
Utils::FilePath FilePath::searchHereAndInParents(const QString &fileName, QDir::Filter type) const
このディレクトリおよびそのすべての親ディレクトリ内で、type 型の「fileName 」という名前のファイルまたはディレクトリを検索します。
最初に見つかった一致結果を返します。一致するものがなければ、空の `FilePath ` を返します。
searchHereAndInParents(const QStringList &, QDir::Filter)も参照してください 。
Utils::FilePath FilePath::searchHereAndInParents(const QStringList &fileNames, QDir::Filter type) const
このディレクトリおよびそのすべての親ディレクトリ内の「fileNames 」にある、type 型のファイルまたはディレクトリを検索します。
最初に見つかった一致を返します。一致が見つからない場合は、空の `FilePath ` を返します。
searchHereAndInParents(const QString &, QDir::Filter)も参照してください 。
Utils::FilePath FilePath::searchInDirectories(const Utils::FilePaths &dirs, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const
dirs で指定された各ディレクトリエントリについて、ファイルパスのmatchScope とfilter が一致する、このオブジェクトに対応するバイナリを検索します。
使用例:
binary = FilePath::fromUrl("docker://123/./make); fullPath = binary.searchInDirectories(binary.deviceEnvironment().path()); assert(fullPath == FilePath::fromUrl("docker://123/usr/bin/make"))
Utils::FilePath FilePath::searchInPath() const
関連するデバイスの PATH 内で、この実行ファイルを検索します。
Utils::FilePath FilePath::searchInPath(const Utils::FilePaths &additionalDirs, Utils::FilePath::PathAmending amending = AppendToPath, const Utils::FilePathPredicate &filter = {}, Utils::FilePath::MatchScope matchScope = WithAnySuffix) const
amending に従って、additionalDirs を追加した関連デバイスの PATH 内で、この実行ファイルを検索します。オプションで、filter を使用して結果をフィルタリングし、matchScope に従って拡張子を処理します。
実行ファイルが見つからない場合は、空のFilePath を返します。
searchAllInPath() およびsearchInDirectories()も参照してください 。
void FilePath::setParts(const QStringView scheme, const QStringView host, const QStringView path)
このFilePath のスキーム、ホスト、およびパス部分を、それぞれscheme 、host 、およびpath に設定します。
fromParts()、scheme()、host()、およびpath()も参照してください 。
Utils::Result<> FilePath::setPermissions(QFileDevice::Permissions permissions) const
このファイルまたはディレクトリの権限をpermissions に設定します。
成功した場合は有効なResult<> を返し、失敗した場合はエラー結果を返します。
permissions() およびmakeWritable()も参照してください 。
QString FilePath::shortNativePath() const
ネイティブの区切り文字を含むパスを返します。Unix では、ホームディレクトリは「~」と省略されます。
toUserOutput() と同等ですが、Unix ではホームディレクトリのプレフィックスを「~」に置き換えます。
[static] void FilePath::sort(Utils::FilePaths &files)
「files 」を、スキーム、ホスト、パスの順に辞書順で並べ替えます。
bool FilePath::startsWithDriveLetter() const
パスが Windows のドライブ文字とそれに続くコロンで始まる場合(例:「C:」)、true を返します。
Utils::FilePath FilePath::stringAppended(const QString &str) const
URL風の文字列表現の末尾に、区切り文字を挿入せずに「str 」を直接付加した、再解析済みのパスを返します。
pathAppended()も参照してください 。
QString FilePath::suffix() const
ファイルのサフィックス(拡張子)を返します。
サフィックスは、ファイル内の最後の「.」以降(ただし「.」自体は含まない)のすべての文字で構成されます。「.ui.qml」の場合、これらは1つのサフィックスとして扱われます。
suffixView()も参照してください 。
QStringView FilePath::suffixView() const
ファイルのサフィックス(拡張子)を `QStringView` の形式で返します。
サフィックスは、ファイル内の最後の「.」以降(ただし、その「.」自体は含まない)のすべての文字で構成されます。「.ui.qml」の場合、これらは1つのサフィックスとして扱われます。
Utils::FilePath FilePath::symLinkTarget() const
これがシンボリックリンクでない場合、空のFilePath を返します。
std::optional<Utils::FilePath> FilePath::tailRemoved(const QString &str) const
パス部分の末尾から「str 」を削除したパスを返します。ただし、パスが「str 」で終わらない場合は、std::nullopt を返します。
Utils::Result<Utils::FilePath> FilePath::tmpDir() const
このパスが属するデバイスの一時ディレクトリを返します。
ローカルパスの場合、これは `QDir::tempPath()` と同等です。リモートデバイスの場合、環境変数 `TMPDIR`、`TEMP`、または `TMP ` が順に確認され、Windows 以外のデバイスではデフォルトとして `"/tmp"` が使用されます。
QString FilePath::toFSPathString() const
QString ベースのAPIに渡すためのQString を返します。
これは /__qtc_devices__/host/path という構成を使用します。
これは、ほとんどの場合、リモート設定やQDir/QFileInfo などでも機能しますが、FilePath を直接使用する場合よりも処理速度が遅いため、FilePath への適切な移植が困難、あるいは不可能な場合(例えば、FilePath を使用しない外部の Qt ベースのライブラリを使用している場合など)にのみ使用すべきです。
fromUserInput()も参照してください 。
QFileInfo FilePath::toFileInfo() const
QFileInfo を返します。
QVariant FilePath::toSettings() const
FilePath を、settingsに保存するのに適したQVariant として返します。
fromSettings() およびtoVariant()も参照してください 。
QUrl FilePath::toUrl() const
QString FilePath::toUrlishString() const
QString ベースのAPIを中継するためのQString を返します。
注:これは 非推奨のAPIであり、適切なFilePath を積極的に活用するか、それが不可能な場合はtoFSPathString() に置き換える必要があります。
これは scheme://host/path の構成を使用し、fromString と合わせて、コードパスを通じてQString を経由してFilePath を渡すために使用されます。
この結果は、QDir やQFileInfo との併用には役立ちません。また、QFileInfo::canonicalFile などの一部の操作によって破棄されてしまいます。
toFSPathString()も参照してください 。
QString FilePath::toUserOutput() const
デバイスのプレフィックスを含め、ユーザーに表示するためのQString を返します。
区切り文字を、このパスが属するシステムのネイティブ形式に変換します。
QVariant FilePath::toVariant() const
FilePath をバリアントとして返します。
QAbstractItemModels におけるストレージなど、型に依存しない内部インターフェースに使用されます。
[static] std::vector<Utils::Result<std::unique_ptr<Utils::FilePathWatcher>>> FilePath::watch(const Utils::FilePaths &paths)
指定された各パスに対して、FilePathWatcher を返します。
返されるFilePathWatcher は、このパスにあるファイルが変更、名前変更、または削除されたときにシグナルを発行します。シグナルは呼び出し元スレッドで発行されます。メインスレッド以外から呼び出された場合、シグナルの発行が始まるまでに時間がかかることがあります。
FilePathWatcherも参照してください 。
Utils::FilePath FilePath::withExecutableSuffix() const
このパスのコピーを返し、その末尾にプラットフォーム固有の実行ファイルの拡張子(Windows では「.exe」など)を追加します。
Utils::FilePath FilePath::withNewMappedPath(const Utils::FilePath &newPath) const
現在のオブジェクトと同じデバイス上のnewPath オブジェクトに対応するパスを返します。
これには、Windows 形式のパスを適切なファイルシステムの大文字小文字の区別やドライブ文字の処理を伴って Unix 形式のパスに変換するなど、デバイス固有の変換が含まれる場合があります:C:/dev/src → /c/dev/src
使用例:
localDir = FilePath("/tmp/workingdir"); executable = FilePath::fromUrl("docker://123/bin/ls") realDir = executable.withNewMappedPath(localDir) assert(realDir == FilePath::fromUrl("docker://123/tmp/workingdir"))
Utils::FilePath FilePath::withNewPath(const QString &newPath) const
現在のオブジェクトと同じデバイス上で、ローカルパスが `newPath ` の `FilePath ` を返します。
使用例:
devicePath = FilePath("docker://123/tmp"); newPath = devicePath.withNewPath("/bin/ls"); assert(realDir == FilePath::fromUrl("docker://123/bin/ls"))
Utils::FilePath FilePath::withSuffix(const QString &suffix) const
このパス文字列に「suffix 」をそのまま追加したコピーを返します。
ファイル拡張子などの接尾辞を追加する場合にこれを使用します。ディレクトリを追加する場合は、代わりに `pathAppended() ` または `operator/() ` を使用してください。
QString FilePath::withTildeHomePath() const
Unix 環境では、ユーザーのホームディレクトリのプレフィックスを「~」に置き換えたパスを返します。これは、クリーンアップ後に `toUrlishString() ` を呼び出すのと同じ効果があります。
Windows またはリモートパスについては、toUrlishString() の結果が変更されずに返されます。
Utils::Result<qint64> FilePath::writeFileContents(const QByteArray &data) const
ファイルにdata を書き込み、既存の内容をすべて上書きします。
成功した場合は書き込まれたバイト数を返し、失敗した場合はエラー結果を返します。
fileContents()も参照してください 。
Utils::FilePath FilePath::operator/(const QString &str) const
このパスに「str 」をパスコンポーネントとして付加したものを返します。これはpathAppended() と同等です。
pathAppended()も参照してください 。
Utils::FilePath &FilePath::operator/=(const QString &str)
str をこのパスのパス構成要素としてその場で追加し、これへの参照を返します。
pathAppended() およびoperator/()も参照してください 。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.