Freigeben über


<filesystem> -Funktionen

Diese kostenlosen Funktionen im <filesystem> Header ändern und abfragen Vorgänge auf Pfaden, Dateien, Symlinks, Verzeichnissen und Volumes. Weitere Informationen und Codebeispiele finden Sie unter File System Navigation (C++) (Dateisystemnavigation (C++)).

absolute

path absolute(const path& pval, const path& base = current_path());

Die Funktion gibt den absoluten Pfadnamen, der pval entspricht, relativ zum Pfadnamen base zurück:

  1. Bei pval.has_root_name() && pval.has_root_directory() gibt die Funktion pval zurück.

  2. Bei pval.has_root_name() && !pval.has_root_directory() gibt die Funktion pval.root_name() / absolute(base).root_directory() / absolute(base).relative_path() / pval.relative_path() zurück.

  3. Bei !pval.has_root_name() && pval.has_root_directory() gibt die Funktion absolute(base).root_name() / pval zurück.

  4. Bei !pval.has_root_name() && !pval.has_root_directory() gibt die Funktion absolute(base) / pval zurück.

begin

const directory_iterator& begin(const directory_iterator& iter) noexcept;
const recursive_directory_iterator&
    begin(const recursive_directory_iterator& iter) noexcept;

Beide Funktionen geben iter zurück.

canonical

path canonical(const path& pval, const path& base = current_path());
path canonical(const path& pval, error_code& ec);
path canonical(const path& pval, const path& base, error_code& ec);

Die Funktionen bilden alle einen absoluten Pfadnamen pabs = absolute(pval, base) (oder pabs = absolute(pval) für die Überladung ohne Basisparameter), und reduzieren Sie ihn dann in der folgenden Schrittfolge auf eine kanonische Form:

  1. Jede Pfadkomponente X , für die is_symlink(X) ersetzt wird true durch read_symlink(X).

  2. Jede Pfadkomponente . (Punkt ist das aktuelle Verzeichnis, das von vorherigen Pfadkomponenten erstellt wurde) wird entfernt.

  3. Jedes Paar von Pfadkomponenten X/.. (dot-dot is the parent directory established by previous path components) is removed.

Die Funktion gibt dann zurück pabs.

copy

void copy(const path& from, const path& to);
void copy(const path& from, const path& to, error_code& ec) noexcept;
void copy(const path& from, const path& to, copy_options opts);
void copy(const path& from, const path& to, copy_options opts, error_code& ec) noexcept;

Die Funktionen kopieren oder verknüpfen möglicherweise eine oder mehrere Dateien von bis zu unter Kontrolleopts, die für copy_options::none die Überladungen ohne opts Parameter verwendet werden. opts muss mindestens eine der folgenden Optionen enthalten:

  • skip_existing, overwrite_existingoder update_existing

  • copy_symlinks oder skip_symlinks

  • directories_only, create_symlinksoder create_hard_links

Die Funktionen bestimmen zunächst die file_status Werte f für undt für folgendes:

  • wenn opts & (copy_options::create_symlinks | copy_options::skip_symlinks), durch Aufrufen symlink_status

  • andernfalls durch Anrufen status

  • Andernfalls wird ein Fehler gemeldet.

Wenn !exists(f) || equivalent(f, t) || is_other(f) || is_other(t) || is_directory(f)&& is_regular_file(t)sie dann einen Fehler melden (und nichts anderes tun).

Andernfalls, wenn is_symlink(f) dann:

  • Wenn options & copy_options::skip_symlinks, führen Sie nichts aus.

  • Andernfalls , wenn !exists(t)&& options & copy_options::copy_symlinks, dann copy_symlink(from, to, opts).

  • Andernfalls melden Sie einen Fehler.

Andernfalls, wenn is_regular_file(f), dann:

  • Wenn opts & copy_options::directories_only, führen Sie nichts aus.

  • Andernfalls , wenn opts & copy_options::create_symlinks, dann create_symlink(to, from).

  • Andernfalls , wenn opts & copy_options::create_hard_links, dann create_hard_link(to, from).

  • Andernfalls , wenn is_directory(f), dann / copy_file(from, tofrom.filename(), opts) .

  • Andernfalls copy_file(from, to, opts).

Andernfalls, wenn is_directory(f) && (opts & copy_options::recursive || !opts), dann:

if (!exists(t))
{  // copy directory contents recursively
    create_directory(to, from, ec);

    for (directory_iterator next(from), end; ec == error_code() && next != end; ++next)
    {
        copy(next->path(), to / next->path().filename(), opts, ec);
    }
}

Andernfalls keinen weiteren Schritt ausführen.

copy_file

bool copy_file(const path& from, const path& to);
bool copy_file(const path& from, const path& to, error_code& ec) noexcept;
bool copy_file(const path& from, const path& to, copy_options opts);
bool copy_file(const path& from, const path& to, copy_options opts, error_code& ec) noexcept;

Die Funktionen kopieren die Datei möglicherweise von bis zu unter Kontrolleopts, die für copy_options::none die Überladungen ohne opts Parameter verwendet wird. opts enthält höchstens einen von skip_existing, overwrite_existing, oder update_existing.

Wenn exists(to) && !(opts & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options::update_existing)), dann melden Sie als Fehler, dass die Datei bereits vorhanden ist.

Andernfalls versuchen Sie, !exists(to) || opts & copy_options::overwrite_existing || opts & copy_options::update_existing&& last_write_time(to) < last_write_time(from) || !(opts & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options:update_existing))den Inhalt und die Attribute der Datei von der Datei in die Datei zu kopieren. Wenn beim Kopierversuch ein Fehler auftritt, diesen dann melden.

Die Funktionen werden zurückgegeben true , wenn die Kopie versucht und erfolgreich ist, andernfalls false.

void copy_symlink(const path& from, const path& to);
void copy_symlink(const path& from, const path& to, error_code& ec) noexcept;

Wenn is_directory(from), ruft die Funktion auf create_directory_symlink(from, to). Andernfalls wird es aufgerufen create_symlink(from, to).

create_directories

bool create_directories(const path& pval);
bool create_directories(const path& pval, error_code& ec) noexcept;

Für einen Pfadnamen wie a\/b\/cz. B. erstellt die Funktion Verzeichnisse a und a\/b nach Bedarf, damit es das Verzeichnis a\/b\/c nach Bedarf erstellen kann. Es wird nur zurückgegeben true , wenn es tatsächlich das Verzeichnis pvalerstellt.

create_directory

bool create_directory(const path& pval);

bool create_directory(const path& pval, error_code& ec) noexcept;
bool create_directory(const path& pval, const path& attr);
bool create_directory(const path& pval, const path& attr, error_code& ec) noexcept;

Die Funktion erstellt das Verzeichnis pval bei Bedarf. Es wird nur zurückgegeben true , wenn das Verzeichnis pvaltatsächlich erstellt wird, in diesem Fall kopiert es Berechtigungen aus der vorhandenen Datei attroder verwendet perms::all für die Überladungen ohne attr Parameter.

void create_directory_symlink(const path& to, const path& link);
void create_directory_symlink(const path& to, const path& link, error_code& ec) noexcept;

Die Funktion erstellt eine Verknüpfung als Symlink zum Verzeichnis.

void create_hard_link(const path& to,  const path& link);
void create_hard_link(const path& to, const path& link, error_code& ec) noexcept;

Die Funktion erstellt eine Verknüpfung als feste Verknüpfung mit dem Verzeichnis oder der Datei.

void create_symlink(const path& to, const path& link);

void create_symlink(const path& to, const path& link, error_code& ec) noexcept;

Die Funktion erstellt link als Symlink zur Datei zu.

current_path

path current_path();
path current_path(error_code& ec);
void current_path(const path& pval);
void current_path(const path& pval, error_code& ec) noexcept;

Die Funktionen ohne den Parameter pval geben den Pfadnamen für das aktuelle Verzeichnis zurück. Die übrigen Funktionen legen das aktuelle Verzeichnis auf pval fest.

end

directory_iterator& end(const directory_iterator& iter) noexcept;
recursive_directory_iterator& end(const recursive_directory_iterator& iter) noexcept;

Die erste Funktion gibt zurück directory_iterator() , und die zweite Funktion gibt zurück. recursive_directory_iterator()

equivalent

bool equivalent(const path& left, const path& right);
bool equivalent(const path& left, const path& right, error_code& ec) noexcept;

Die Funktionen werden nur zurückgegeben true , wenn links und rechts dieselbe Dateisystementität ausgewählt werden.

exists

bool exists(file_status stat) noexcept;
bool exists(const path& pval);
bool exists(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt status_known && stat.type() != file_not_found zurück. Die zweite und dritte Funktion geben zurück exists(status(pval)).

file_size

uintmax_t file_size(const path& pval);
uintmax_t file_size(const path& pval, error_code& ec) noexcept;

Die Funktionen geben die Größe in Byte der ausgewählten pvalDatei zurück, wenn exists(pval) && is_regular_file(pval) und die Dateigröße bestimmt werden kann. Andernfalls melden sie einen Fehler und geben zurück uintmax_t(-1).

uintmax_t hard_link_count(const path& pval);
uintmax_t hard_link_count(const path& pval, error_code& ec) noexcept;

Die Funktion gibt die Anzahl der harten Verknüpfungen für pvaloder -1 zurück, wenn ein Fehler auftritt.

hash_value

size_t hash_value(const path& pval) noexcept;

Die Funktion gibt einen Hashwert für pval.native().

is_block_file

bool is_block_file(file_status stat) noexcept;
bool is_block_file(const path& pval);
bool is_block_file(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::block zurück. Die re Standard ing-Funktionen geben zurückis_block_file(status(pval)).

is_character_file

bool is_character_file(file_status stat) noexcept;
bool is_character_file(const path& pval);
bool is_character_file(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::character zurück. Die re Standard ing-Funktionen geben zurückis_character_file(status(pval)).

is_directory

bool is_directory(file_status stat) noexcept;
bool is_directory(const path& pval);
bool is_directory(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::directory zurück. Die re Standard ing-Funktionen geben zurückis_directory_file(status(pval)).

is_empty

bool is_empty(file_status stat) noexcept;
bool is_empty(const path& pval);
bool is_empty(const path& pval, error_code& ec) noexcept;

Wenn is_directory(pval), dann gibt die Funktion zurück directory_iterator(pval) == directory_iterator(); andernfalls wird sie zurückgegeben file_size(pval) == 0.

is_fifo

bool is_fifo(file_status stat) noexcept;
bool is_fifo(const path& pval);
bool is_fifo(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::fifo zurück. Die re Standard ing-Funktionen geben zurückis_fifo(status(pval)).

is_other

bool is_other(file_status stat) noexcept;
bool is_other(const path& pval);
bool is_other(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::other zurück. Die re Standard ing-Funktionen geben zurückis_other(status(pval)).

is_regular_file

bool is_regular_file(file_status stat) noexcept;
bool is_regular_file(const path& pval);
bool is_regular_file(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::regular zurück. Die re Standard ing-Funktionen geben zurückis_regular_file(status(pval)).

is_socket

bool is_socket(file_status stat) noexcept;
bool is_socket(const path& pval);
bool is_socket(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::socket zurück. Die re Standard ing-Funktionen geben zurückis_socket(status(pval)).

bool is_symlink(file_status stat) noexcept;
bool is_symlink(const path& pval);
bool is_symlink(const path& pval, error_code& ec) noexcept;

Diese erste Funktion gibt stat.type() == file_type::symlink zurück. Die re Standard ing-Funktionen geben zurückis_symlink(status(pval)).

last_write_time

file_time_type last_write_time(const path& pval);
file_time_type last_write_time(const path& pval, error_code& ec) noexcept;
void last_write_time(const path& pval, file_time_type new_time);
void last_write_time(const path& pval, file_time_type new_time, error_code& ec) noexcept;

Die ersten beiden Funktionen geben den Zeitpunkt der letzten Datenänderung für pval, oder file_time_type(-1) wenn ein Fehler auftritt. Die letzten beiden Funktionen legen den Zeitpunkt der letzten Datenänderung auf pvalnew_time.

permissions

void permissions(const path& pval, perms mask);
void permissions(const path& pval, perms mask, error_code& ec) noexcept;

Die Funktionen legen die Berechtigungen für den Pfadnamen fest, der unter pval Kontrolle von perms & (perms::add_perms | perms::remove_perms).mask & perms::mask mask enthält höchstens einen von perms::add_perms und perms::remove_perms.

Wenn mask & perms::add_perms, legen die Funktionen die Berechtigungen auf status(pval).permissions() | mask & perms::mask. mask & perms::remove_permsAndernfalls legen die Funktionen die Berechtigungen auf status(pval).permissions() & ~(mask & perms::mask). Andernfalls legen die Funktionen die Berechtigungen auf mask & perms::mask.

proximate

path proximate(const path& p, error_code& ec);
path proximate(const path& p, const path& base = current_path());
path proximate(const path& p, const path& base, error_code& ec);
path read_symlink(const path& pval);
path read_symlink(const path& pval, error_code& ec);

Die Funktionen melden einen Fehler und geben zurück path() , wenn !is_symlink(pval). Andernfalls geben die Funktionen ein Objekt vom Typ path zurück, das die symbolische Verknüpfung enthält.

relative

path relative(const path& p, error_code& ec);
path relative(const path& p, const path& base = current_path());
path relative(const path& p, const path& base, error_code& ec);

remove

bool remove(const path& pval);
bool remove(const path& pval, error_code& ec) noexcept;

Die Funktionen werden nur zurückgegeben true , wenn exists(symlink_status(pval)) die Datei erfolgreich entfernt wird. Ein Symlink wird selbst entfernt, nicht die ausgewählte Datei.

remove_all

uintmax_t remove_all(const path& pval);
uintmax_t remove_all(const path& pval, error_code& ec) noexcept;

Wenn pval ein Verzeichnis ist, entfernen die Funktionen alle Verzeichniseinträge rekursiv und dann den Eintrag selbst. Andernfalls rufen die Funktionen auf remove. Sie geben die Anzahl aller Elemente zurück, die erfolgreich entfernt wurden.

rename

void rename(const path& from, const path& to);
void rename(const path& from, const path& to, error_code& ec) noexcept;

Die Funktionen werden von in "in" umbenannt. Ein Symlink wird selbst umbenannt, nicht die ausgewählte Datei.

resize_file

void resize(const path& pval, uintmax_t size);
void resize(const path& pval, uintmax_t size, error_code& ec) noexcept;

Die Funktionen ändern die Größe einer Datei so, dass file_size(pval) == size

space

space_info space(const path& pval);
space_info space(const path& pval, error_code& ec) noexcept;

Die Funktion gibt Informationen über das von pval, in einer Struktur vom Typ space_infoausgewählte Volume zurück. Die Struktur enthält uintmax_t(-1) einen beliebigen Wert, der nicht bestimmt werden kann.

status

file_status status(const path& pval);
file_status status(const path& pval, error_code& ec) noexcept;

Die Funktionen geben den Pfadnamenstatus, den Dateityp und die Berechtigungen zurück, die zugeordnet sind pval. Ein Symlink wird selbst nicht getestet, aber die datei, die er auswäht.

status_known

bool status_known(file_status stat) noexcept;

Die Funktion gibt zurück. stat.type() != file_type::none

swap

void swap(path& left, path& right) noexcept;

Die Funktion tauscht den Inhalt von links und rechts aus.

file_status symlink_status(const path& pval);
file_status symlink_status(const path& pval, error_code& ec) noexcept;

Die Funktionen geben den Pfadnamen symlink-Status, den Dateityp und berechtigungen zurück, die zugeordnet sind pval. Die Funktionen verhalten sich genauso, als status(pval) ob ein Symlink selbst getestet wird, nicht die ausgewählte Datei.

system_complete

path system_complete(const path& pval);
path system_complete(const path& pval, error_code& ec);

Die Funktionen geben einen absoluten Pfadnamen zurück, der bei Bedarf das aktuelle Verzeichnis berücksichtigt, das seinem Stammnamen zugeordnet ist. (Für POSIX geben die Funktionen zurück absolute(pval)).

temp_directory_path

path temp_directory_path();
path temp_directory_path(error_code& ec);

Die Funktionen geben einen Pfadnamen für ein Verzeichnis zurück, das für die Aufnahme temporärer Dateien geeignet ist.

u8path

template <class Source>
path u8path(const Source& source);

template <class InIt>
path u8path(InIt first, InIt last);

Die erste Funktion verhält sich genauso wie path(source) die zweite Funktion wie die zweite Funktion, path(first, last) mit der Ausnahme, dass die ausgewählte Quelle in jedem Fall als Sequenz von Zeichenelementen verwendet wird, die als UTF-8 codiert sind, unabhängig vom Dateisystem.

weakly_canonical

path weakly_canonical(const path& p);
path weakly_canonical(const path& p, error_code& ec);