file_type_enum 1.0.0

An enum with a variant for each file type.
Documentation

file_type_enum

Crates.io Docs.rs License

An enum with a variant for each file type.

pub enum FileType {
    Regular,
    Directory,
    Symlink,
    BlockDevice, // unix only
    CharDevice,  // unix only
    Fifo,        // unix only
    Socket,      // unix only
}

If you don't need an enum, check these methods from std instead:

  • [Path::is_file].
  • [Path::is_dir].
  • [Path::is_symlink].

Example

use file_type_enum::FileType;

fn main() -> io::Result<()> {
    let file_type = FileType::from_path("/tmp")?;

    println!("There's a {} at {}!", file_type, path);
    // Out:  "There's a directory at /tmp!"

    Ok(())
}

Note that the [FileType::from_path] follows symlinks and [FileType::from_symlink_path] does not.

Conversions

Contributing

Issues and PRs are welcome.

License: MIT