Namespaces
Variants

std::experimental::filesystem:: equivalent

From cppreference.net
Definiert im Header <experimental/filesystem>
bool equivalent ( const path & p1, const path & p2 ) ;
bool equivalent ( const path & p1, const path & p2, error_code & ec ) ;
(1) (filesystem TS)

Überprüft, ob die Pfade p1 und p2 auf dieselbe Datei oder dasselbe Verzeichnis verweisen und denselben Dateistatus haben, wie durch status bestimmt (Symlinks werden verfolgt).

Wenn p1 oder p2 nicht existiert oder deren Dateityp nicht Datei, Verzeichnis oder symbolischer Link ist (wie durch is_other bestimmt), wird ein Fehler gemeldet.

Die nicht-werfende Überladung gibt bei Fehlern false zurück.

Inhaltsverzeichnis

Parameter

p1, p2 - Pfade zur Äquivalenzprüfung
ec - Out-Parameter für Fehlerberichterstattung in der nicht-werfenden Überladung

Rückgabewert

true wenn p1 und p2 auf dieselbe Datei oder dasselbe Verzeichnis verweisen und ihr Dateistatus identisch ist. false andernfalls.

Ausnahmen

The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p1 as the first argument, p2 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

Hinweise

Zwei Pfade werden als identische Dateisystem-Entitäten betrachtet, wenn st_dev und st_ino ihrer POSIX stat structure , ermittelt wie durch POSIX stat , gleich sind (was bedeutet, dass die Dateien auf demselben Gerät an derselben Position gespeichert sind).

Insbesondere sind alle Hardlinks für dieselbe Datei oder dasselbe Verzeichnis äquivalent, und ein Symlink und sein Ziel auf demselben Dateisystem sind äquivalent.

Beispiel

#include <cstdint>
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    // hard link equivalency
    fs::path p1 = ".";
    fs::path p2 = fs::current_path();
    if (fs::equivalent(p1, p2))
        std::cout << p1 << " is equivalent to " << p2 << '\n';
    // symlink equivalency
    fs::path p3 = "/lib/libc.so.6";
    fs::path p4 = p3.parent_path() / fs::read_symlink(p3);
    if (fs::equivalent(p3, p4))
        std::cout << p3 << " is equivalent to " << p4 << '\n';
}

Mögliche Ausgabe:

"." is equivalent to "/var/tmp/test"
"/lib/libc.so.6" is equivalent to "/lib/libc-2.12.so"

Siehe auch

Bestimmt Dateiattribute
Bestimmt Dateiattribute, überprüft das Symlink-Ziel
(Funktion)