Skip to content

Commit 094b893

Browse files
Rollup merge of #144975 - joshtriplett:file-times-dir, r=jhpratt
`File::set_times`: Update documentation and example to support setting timestamps on directories Inspired by #123883 .
2 parents 09de71b + e597071 commit 094b893

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/std/src/fs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,11 @@ impl File {
11111111
/// `futimes` on macOS before 10.13) and the `SetFileTime` function on Windows. Note that this
11121112
/// [may change in the future][changes].
11131113
///
1114+
/// On most platforms, including UNIX and Windows platforms, this function can also change the
1115+
/// timestamps of a directory. To get a `File` representing a directory in order to call
1116+
/// `set_times`, open the directory with `File::open` without attempting to obtain write
1117+
/// permission.
1118+
///
11141119
/// [changes]: io#platform-specific-behavior
11151120
///
11161121
/// # Errors
@@ -1128,7 +1133,7 @@ impl File {
11281133
/// use std::fs::{self, File, FileTimes};
11291134
///
11301135
/// let src = fs::metadata("src")?;
1131-
/// let dest = File::options().write(true).open("dest")?;
1136+
/// let dest = File::open("dest")?;
11321137
/// let times = FileTimes::new()
11331138
/// .set_accessed(src.accessed()?)
11341139
/// .set_modified(src.modified()?);

0 commit comments

Comments
 (0)