Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Diese kostenlosen Funktionen im C++17-Header <filesystem> führen Änderungs- und Abfragevorgänge für Pfade, Dateien, Symlinks, Verzeichnisse und Volumes aus. Weitere Informationen und Codebeispiele finden Sie unter File System Navigation (C++) (Dateisystemnavigation (C++)).
Hinweis
In diesem Artikel werden die C++17-Funktionen std::filesystem dokumentiert. Informationen zu den historischen Vorstandardfunktionen, die MSVC bereitgestellt <experimental/filesystem>hat, finden Sie unter <experimental/filesystem> "Funktionen".
Anforderungen
Kopfball:<filesystem>
Namespace:std::filesystem
absolute
path absolute(const path& pval);
path absolute(const path& pval, error_code& ec);
Die Funktionen erstellen einen absoluten Pfad, der sich auf denselben Dateisystemspeicherort bezieht wie pvaldie Betriebssystemsemantik. Die Überladung, die zurückgegeben ecpath() wird, wenn ein Fehler auftritt.
begin
directory_iterator begin(directory_iterator iter) noexcept;
recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
Beide Funktionen geben iter zurück. Zusammen mit end, ermöglichen sie bereichsbasierte for Schleifen über eine directory_iterator oder recursive_directory_iterator.
canonical
path canonical(const path& pval);
path canonical(const path& pval, error_code& ec);
Die Funktionen konvertieren pval, die vorhanden sein müssen, in einen absoluten Pfad, der sich auf dasselbe Dateisystemobjekt bezieht und keine symbolischen Verknüpfungs-, Punkt- oder Punkt-Punkte-Elemente aufweist. Die Überladung, die zurückgegeben ecpath() wird, wenn ein Fehler auftritt.
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
opts muss mindestens eine der folgenden Optionen enthalten:
skip_existing,overwrite_existingoderupdate_existingcopy_symlinksoderskip_symlinksdirectories_only,create_symlinksodercreate_hard_links
Die Funktionen bestimmen zuerst die file_status Werte f für undt von zu zu. Sie werden verwendetsymlink_status, wenn opts sie die Quelle oder das Ziel enthalten copy_options::skip_symlinkscopy_options::create_symlinks, oder copy_options::copy_symlinks, wie für die Quelle oder das Ziel erforderlich. Andernfalls verwenden statussie .
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, danncopy_symlink(from, to).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, danncreate_symlink(from, to).Andernfalls , wenn
opts & copy_options::create_hard_links, danncreate_hard_link(from, to).Andernfalls , wenn
is_directory(t), danncopy_file(from, to / from.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
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.
copy_symlink
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.
create_directory_symlink
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.
create_hard_link
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.
create_symlink
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&) noexcept;
recursive_directory_iterator end(const recursive_directory_iterator&) 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) && stat.type() != file_type::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).
hard_link_count
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 verbleibenden Funktionen geben zurück is_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 verbleibenden Funktionen geben zurück is_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 verbleibenden Funktionen geben zurück is_directory(status(pval)).
is_empty
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 verbleibenden Funktionen geben zurück is_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 exists(stat) && !is_regular_file(stat) && !is_directory(stat) && !is_symlink(stat) zurück. Die verbleibenden Funktionen geben zurück is_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 verbleibenden Funktionen geben zurück is_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 verbleibenden Funktionen geben zurück is_socket(status(pval)).
is_symlink
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 verbleibenden Funktionen geben zurück is_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, perm_options opts = perm_options::replace);
void permissions(const path& pval, perms mask, error_code& ec) noexcept;
void permissions(const path& pval, perms mask, perm_options opts, error_code& ec);
Die Funktionen legen die Berechtigungen für den Pfadnamen fest, der unter pval Kontrolle von mask & perms::mask.opts
optsmuss genau eine von perm_options::replace, , oder perm_options::remove, und optional enthalten perm_options::nofollowperm_options::add. Die Überladungen ohne opts Parameter verhalten sich wie folgtperm_options::replaceopts.
Wenn opts & perm_options::add, legen die Funktionen die Berechtigungen auf status(pval).permissions() | (mask & perms::mask).
opts & perm_options::removeAndernfalls legen die Funktionen die Berechtigungen auf status(pval).permissions() & ~(mask & perms::mask). Andernfalls legen die Funktionen die Berechtigungen auf mask & perms::mask. Wenn opts & perm_options::nofollow und pval eine symbolische Verknüpfung benannt wird, ändern die Funktionen die Berechtigungen der symbolischen Verknüpfung selbst und nicht die Datei, in die sie aufgelöst wird.
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);
Die erste Überladung gibt zurück proximate(p, current_path(), ec). Die anderen Überladungen geben das Ergebnis der Anwendung lexically_proximate auf die schwach kanonischen Formen von p und base. Die Überladung, die zurückgegeben ecpath() wird, wenn ein Fehler auftritt.
read_symlink
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);
Die erste Überladung gibt zurück relative(p, current_path(), ec). Die anderen Überladungen geben das Ergebnis der Anwendung lexically_relative auf die schwach kanonischen Formen von p und base. Die Überladung, die zurückgegeben ecpath() wird, wenn ein Fehler auftritt.
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_file(const path& pval, uintmax_t size);
void resize_file(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.
symlink_status
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.
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);
Diese Funktionen geben einen Pfad in kanonischer Form zurück, z. B. die canonical Funktion, aber der Pfad muss nicht vorhanden sein.
Siehe auch
Headerdateienreferenz
<filesystem>
Dateisystemnavigation (C++)