Namespaces
Variants

std::experimental::filesystem:: canonical

From cppreference.net
Definiert im Header <experimental/filesystem>
path canonical ( const path & p, const path & base = current_path ( ) ) ;
(1) (Filesystem TS)
path canonical ( const path & p, error_code & ec ) ;
(2) (Filesystem TS)
path canonical ( const path & p, const path & base, error_code & ec ) ;
(3) (Filesystem TS)

Konvertiert den Pfad p in einen kanonischen absoluten Pfad, d.h. einen absoluten Pfad ohne Punkt-, Punkt-Punkt-Elemente oder symbolische Links.

Wenn p kein absoluter Pfad ist, verhält sich die Funktion so, als ob sie zuerst durch absolute ( p, base ) oder absolute ( p ) für (2) absolut gemacht würde.

Der Pfad p muss existieren.

Inhaltsverzeichnis

Parameter

p - ein Pfad, der absolut oder relativ zu base sein kann und ein existierender Pfad sein muss
base - Basis-Pfad, der verwendet wird, falls p relativ ist
ec - Fehlercode, in dem der Fehlerstatus gespeichert wird

Rückgabewert

Ein absoluter Pfad, der zur selben Datei aufgelöst wird wie absolute ( p, base ) (oder absolute ( p ) für (2) ).

Ausnahmen

The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument, base as the second argument, and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has
noexcept Spezifikation:
noexcept

Diese Funktion orientiert sich an der POSIX-Funktion realpath .

Beispiel

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    fs::path p = fs::path("..") / ".." / "AppData";
    std::cout << "Current path is " << fs::current_path() << '\n'
              << "Canonical path for " << p << " is " << fs::canonical(p) << '\n';
}

Mögliche Ausgabe:

Current path is "C:\Users\abcdef\AppData\Local\Temp"
Canonical path for "..\..\AppData" is "C:\Users\abcdef\AppData"

Siehe auch

repräsentiert einen Pfad
(Klasse)
erstellt einen absoluten Pfad
konvertiert einen Pfad in einen absoluten Pfad unter Nachbildung des betriebssystemspezifischen Verhaltens
(Funktion)