How to get the path to the file name?

I want to get the path to the file name in MATLAB, for example dirname, and basenameon Linux. I tried to find a function like strrchr, but I failed. I know that strtok, strfindand textscancan be used, but I want to accomplish this with no more than two operators.

+5
source share
2 answers

For this specific problem, I suggest you use the function : fileparts

[path, filename, extension] = fileparts(str)
+8
source

The answer to Nick definitely does what you ask for, but here is an alternative answer using regexprep:

regexprep(str, '(.+)(?:\\|/)(.*)', '$1')

( ), $2 $1. , MATLAB .

+3

All Articles