Rust filesystem: Difference between revisions
From wikinotes
(Created page with "= Documentation = <blockquote> {| class="wikitable" |- | <code>std::fs</code> || https://doc.rust-lang.org/std/fs/index.html |- | <code>std::path</code> || https://doc.rust-lang.org/std/path/index.html |- | <code>std::env</code> || https://doc.rust-lang.org/std/env/index.html |- |} </blockquote><!-- Documentation --> = Locations = <blockquote> <syntaxhighlight lang="rust"> std::env::home_dir() // get user's home directory </syntaxhighlight> </blockquote><!-- Loca...") |
|||
Line 42: | Line 42: | ||
std::fs::remove_dir // remove empty dir | std::fs::remove_dir // remove empty dir | ||
std::fs::remove_dir_all() // remove files from dir, then dir (recursive?) | std::fs::remove_dir_all() // remove files from dir, then dir (recursive?) | ||
std::fs::remove_file() | std::fs::remove_file() // remove a file | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Filesystem --> | </blockquote><!-- Filesystem --> |
Revision as of 01:24, 9 February 2023
Documentation
std::fs
https://doc.rust-lang.org/std/fs/index.html std::path
https://doc.rust-lang.org/std/path/index.html std::env
https://doc.rust-lang.org/std/env/index.html
Locations
std::env::home_dir() // get user's home directory
Filesystem
Some common filesystem operations
use std::fs; use std::env; use std::os::unix::fs; std::os::unix::fs::chown() // chown std::fs::set_permissions() // chmod std::env::current_dir() // cwd/pwd std::fs::copy() // copy file to another std::fs::soft_link() // create symlink std::fs::rename() // rename/move a file std::fs::create_dir() // mkdir std::fs::create_dir_all() // mkdir -p std::fs::read_dir() // list dirs/files in dir (non-recursive) std::fs::remove_dir // remove empty dir std::fs::remove_dir_all() // remove files from dir, then dir (recursive?) std::fs::remove_file() // remove a file