This is supported on Unix only.
Expand description
Returns the ID of the device containing the file.
use std::io;
use std::fs;
use std::os::unix::fs::MetadataExt;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let dev_id = meta.dev();
Ok(())
}
Run
Returns the inode number.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let inode = meta.ino();
Ok(())
}
Run
Returns the rights applied to this file.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let mode = meta.mode();
let user_has_write_access = mode & 0o200;
let user_has_read_write_access = mode & 0o600;
let group_has_read_access = mode & 0o040;
let others_have_exec_access = mode & 0o001;
Ok(())
}
Run
Returns the number of hard links pointing to this file.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nb_hard_links = meta.nlink();
Ok(())
}
Run
Returns the user ID of the owner of this file.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let user_id = meta.uid();
Ok(())
}
Run
Returns the group ID of the owner of this file.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let group_id = meta.gid();
Ok(())
}
Run
Returns the device ID of this file (if it is a special one).
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let device_id = meta.rdev();
Ok(())
}
Run
Returns the total size of this file in bytes.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let file_size = meta.size();
Ok(())
}
Run
Returns the last access time of the file, in seconds since Unix Epoch.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let last_access_time = meta.atime();
Ok(())
}
Run
Returns the last access time of the file, in nanoseconds since atime
.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nano_last_access_time = meta.atime_nsec();
Ok(())
}
Run
Returns the last modification time of the file, in seconds since Unix Epoch.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let last_modification_time = meta.mtime();
Ok(())
}
Run
Returns the last modification time of the file, in nanoseconds since mtime
.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nano_last_modification_time = meta.mtime_nsec();
Ok(())
}
Run
Returns the last status change time of the file, in seconds since Unix Epoch.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let last_status_change_time = meta.ctime();
Ok(())
}
Run
Returns the last status change time of the file, in nanoseconds since ctime
.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let nano_last_status_change_time = meta.ctime_nsec();
Ok(())
}
Run
Returns the block size for filesystem I/O.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let block_size = meta.blksize();
Ok(())
}
Run
Returns the number of blocks allocated to the file, in 512-byte units.
Please note that this may be smaller than st_size / 512
when the file has holes.
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::io;
fn main() -> io::Result<()> {
let meta = fs::metadata("some_file")?;
let blocks = meta.blocks();
Ok(())
}
Run