File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: path:: Path ;
2+
3+ /// Returns `true` if the path points at an existing entity.
4+ ///
5+ /// This function will traverse symbolic links to query information about the
6+ /// destination file.
7+ ///
8+ /// # Examples
9+ ///
10+ /// ```rust,no_run
11+ /// # use tokio::fs;
12+ ///
13+ /// # #[tokio::main]
14+ /// # async fn main() {
15+ /// let exists = fs::exists("/some/file/path.txt").await;
16+ /// // in case the `/some/file/path.txt` points to existing path
17+ /// assert_eq!(exists, true);
18+ /// # }
19+ /// ```
20+ ///
21+ /// # Note
22+ ///
23+ /// This method returns false in case of errors thus ignoring them. Use [`fs::metadata`][super::metadata]
24+ /// if you want to check for errors.
25+ pub async fn exists ( path : impl AsRef < Path > ) -> bool {
26+ super :: metadata ( & path) . await . is_ok ( )
27+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ pub use self::create_dir_all::create_dir_all;
3636mod dir_builder;
3737pub use self :: dir_builder:: DirBuilder ;
3838
39+ mod exists;
40+ pub use self :: exists:: exists;
41+
3942mod file;
4043pub use self :: file:: File ;
4144
You can’t perform that action at this time.
0 commit comments