Cut-off PathBuf based on delimiter

Hello!

Suppose I have a PathBuf variable as:

"data/Part_0000.bi4"

or:

"some-more-complex-directory/fun/data/Part_0000.bi4"

No matter the case, I want it to remove everything before and including the last "/", so in both cases it should return:

"Part_0000.bi4"

Is there an easy way to do this?

Kind regards

You can use the Path::file_name method.

docs
https://doc.rust-lang.org/nightly/std/path/struct.Path.html#method.file_name

example
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=470db63c5b9ce0be3e8dc9676c94771e

Thanks! Works perfectly on my PathBuf variable.

Kind regards

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.