std::experimental::filesystem:: create_symlink, std::experimental::filesystem:: create_directory_symlink
|
Definido en el encabezado
<experimental/filesystem>
|
||
|
void
create_symlink
(
const
path
&
target,
const
path
&
link
)
;
void create_symlink ( const path & target, const path & link, error_code & ec ) ; |
(1) | (filesystem TS) |
|
void
create_directory_symlink
(
const
path
&
target,
const
path
&
link
)
;
void create_directory_symlink ( const path & target, const path & link, error_code & ec ) ; |
(2) | (filesystem TS) |
Crea un enlace simbólico link con su destino establecido en target como si fuera mediante POSIX symlink() : la ruta target puede ser inválida o no existir.
Algunos sistemas operativos requieren la creación de enlaces simbólicos para identificar que el enlace es a un directorio. El código portable debe usar (2) para crear enlaces simbólicos de directorio en lugar de (1) , aunque no hay distinción en sistemas POSIX.
Contenidos |
Parámetros
| target | - | ruta a la que apuntará el enlace simbólico, no tiene que existir |
| link | - | ruta del nuevo enlace simbólico |
| ec | - | parámetro de salida para reporte de errores en la sobrecarga que no lanza excepciones |
Valor de retorno
(ninguno)
Excepciones
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with target as the first argument, enlace 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 hasNotas
Algunos sistemas operativos no admiten enlaces simbólicos en absoluto o solo los admiten para archivos regulares.
Algunos sistemas de archivos no admiten enlaces simbólicos independientemente del sistema operativo, por ejemplo el sistema FAT utilizado en algunas tarjetas de memoria y unidades flash.
Al igual que un enlace físico, un enlace simbólico permite que un archivo tenga múltiples nombres lógicos. La presencia de un enlace físico garantiza la existencia de un archivo, incluso después de que se haya eliminado el nombre original. Un enlace simbólico no ofrece tal garantía; de hecho, el archivo nombrado por el target argumento no necesita existir cuando se crea el enlace. Un enlace simbólico puede cruzar límites de sistemas de archivos.
Ejemplo
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::create_directories("sandbox/subdir"); fs::create_symlink("target", "sandbox/sym1"); fs::create_directory_symlink("subdir", "sandbox/sym2"); for (auto it = fs::directory_iterator("sandbox"); it != fs::directory_iterator(); ++it) if (is_symlink(it->symlink_status())) std::cout << *it << "->" << read_symlink(*it) << '\n'; fs::remove_all("sandbox"); }
Salida posible:
"sandbox/sym1"->"target" "sandbox/sym2"->"subdir"
Véase también
|
determina los atributos del archivo
determina los atributos del archivo, verificando el destino del enlace simbólico (función) |
|
|
obtiene el destino de un enlace simbólico
(función) |
|
|
crea un enlace físico
(función) |