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

example

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.