Expand description
(Deprecated) Rust’s once-missing utime function
This crate was originally created to provide a missing utime function for Rust, allowing users to set the atime/mtime of a file, as the Rust standard library did not offer a stable method for this functionality.
As of Rust 1.75.0, the standard library now includes File::set_times
, which
provides a stable and native way to update a file’s last modification and access
time.
§Recommendation
If you are using Rust 1.75.0 or later, it is recommended to use the native
File::set_times
function instead of this crate.
use std::fs::{File, FileTimes};
use std::time::SystemTime;
let times = FileTimes::new()
.set_accessed(SystemTime::now())
.set_modified(SystemTime::UNIX_EPOCH);
File::create("target/testdummy")?.set_times(times)?;
§For Rust <1.75.0 users
For projects using older Rust versions, you may still find this library useful. See documentation for the further details.
use std::fs::File;
use utime::*;
File::create("target/testdummy")?;
set_file_times("target/testdummy", 1000000, 1000000000)?;
let (accessed, modified) = get_file_times("target/testdummy")?;
assert_eq!(accessed, 1000000);
assert_eq!(modified, 1000000000);
Functions§
- get_
file_ times Deprecated - Retrieve the timestamps for a file’s last modification and access time.
- set_
file_ times Deprecated - Changes the timestamps for a file’s last modification and access time.