The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Check If A File Exists In Rust

TODO: Pull subtitle into page object
Code
use std::path::PathBuf;

fn main() {
    let file_path = PathBuf::from("files/alfa.txt");
    dbg!(file_exists(file_path));
}

fn file_exists(path: PathBuf) -> bool {
    match path.try_exists() {
        Ok(exists) => {
            if exists == true {
                true
            } else {
                false
            }
        }
        Err(_) => {
            false
        }
    }
}
Results
[_active_nvim_run:5] file_exists(file_path) = true

The is the basic way to check if a file exists using `.try_exists()`rust` instead of `.exists()`rust`. The difference between the two is that `.try_exists()`rust` will produce an `Err`` for things like permissions issues or broken symbolic links.

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Check If A File Exists In Rust

-- code
-- rust

use std::path::PathBuf;

fn main() {
    let file_path = PathBuf::from("files/alfa.txt");
    dbg!(file_exists(file_path));
}

fn file_exists(path: PathBuf) -> bool {
    match path.try_exists() {
        Ok(exists) => {
            if exists == true {
                true
            } else {
                false
            }
        }
        Err(_) => {
            false
        }
    }
}

-- results/

[_active_nvim_run:5] file_exists(file_path) = true

-- /results

-- p


The is the basic way to check if a file exists using `.try_exists()`rust`
instead of `.exists()`rust`. The difference between the two is that 
`.try_exists()`rust` will produce an `Err`` for things like permissions
issues or broken symbolic links.


-- ref
-- title: Rust Struct std::path::PathBuf .try_exists()
-- url: https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#method.try_exists

-- ref
-- title: Rust Struct std::path::PathBuf .exists()
-- url: https://doc.rust-lang.org/stable/std/path/struct.PathBuf.html#method.exists

-- categories
-- Rust 

-- metadata
-- date: 2023-06-29 14:03:02
-- id: 2rtg5n3b
-- site: aws
-- type: post
-- status: published