Path

Struct Path 

Source
pub struct Path { /* private fields */ }
Expand description

Concrete path - includes filesystem operations

Implementations§

Source§

impl Path

Source

pub fn new<P: AsRef<StdPath>>(path: P) -> Self

Create new Path

Source

pub fn cwd() -> Result<Path, PyException>

Current working directory

Source

pub fn home() -> Result<Path, PyException>

Home directory

Source

pub fn absolute(&self) -> Result<Path, PyException>

Get absolute path

Source

pub fn resolve(&self) -> Result<Path, PyException>

Resolve path (follow symlinks)

Source

pub fn exists(&self) -> bool

Check if path exists

Source

pub fn is_file(&self) -> bool

Check if path is file

Source

pub fn is_dir(&self) -> bool

Check if path is directory

Check if path is symlink

Source

pub fn stat(&self) -> Result<FileStats, PyException>

Get file statistics

Source

pub fn mkdir(&self, parents: bool, exist_ok: bool) -> Result<(), PyException>

Create directory

Source

pub fn rmdir(&self) -> Result<(), PyException>

Remove directory

Remove file

Source

pub fn iterdir(&self) -> Result<Vec<Path>, PyException>

List directory contents

Source

pub fn glob(&self, pattern: &str) -> Result<Vec<Path>, PyException>

Glob pattern matching

Source

pub fn rglob(&self, pattern: &str) -> Result<Vec<Path>, PyException>

Recursive glob

Source

pub fn read_text(&self, _encoding: Option<&str>) -> Result<String, PyException>

Read text file

Source

pub fn write_text<S: AsRef<str>>(&self, data: S) -> Result<(), PyException>

Write text file

Source

pub fn read_bytes(&self) -> Result<Vec<u8>, PyException>

Read bytes

Source

pub fn write_bytes(&self, data: &[u8]) -> Result<(), PyException>

Write bytes

Methods from Deref<Target = PurePath>§

Source

pub fn parts(&self) -> Vec<String>

Get path parts

Source

pub fn drive(&self) -> String

Get drive (Windows only)

Source

pub fn root(&self) -> String

Get root

Source

pub fn anchor(&self) -> String

Get anchor (drive + root)

Source

pub fn parent(&self) -> PurePath

Get parent directory

Source

pub fn parents(&self) -> Vec<PurePath>

Get all parents

Source

pub fn name(&self) -> String

Get file name

Source

pub fn suffix(&self) -> String

Get file suffix

Source

pub fn suffixes(&self) -> Vec<String>

Get all suffixes

Source

pub fn stem(&self) -> String

Get stem (filename without final suffix)

Source

pub fn joinpath<P: AsRef<StdPath>>(&self, other: P) -> PurePath

Join with other path

Source

pub fn match_pattern(&self, pattern: &str) -> bool

Check if path matches pattern

Source

pub fn relative_to(&self, other: &PurePath) -> Result<PurePath, PyException>

Get relative path to other

Source

pub fn is_absolute(&self) -> bool

Check if path is absolute

Source

pub fn is_relative(&self) -> bool

Check if path is relative

Source

pub fn as_posix(&self) -> String

Convert to string

Source

pub fn with_name<S: AsRef<str>>(&self, name: S) -> PurePath

Replace path components

Source

pub fn with_suffix<S: AsRef<str>>(&self, suffix: S) -> PurePath

Replace suffix

Trait Implementations§

Source§

impl Clone for Path

Source§

fn clone(&self) -> Path

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Path

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Path

Source§

type Target = PurePath

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for Path

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for Path

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Path

Source§

fn from(s: String) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,