Reputation: 27
Ball='C:\----\--\Documents\----\ -----\ Ball - BEST';
Given the path to a directory, how do you save the immediate directory as a character string?
Upvotes: 0
Views: 462
Reputation: 115
You can use the UNIX command "pwd"
% On C:\----\--\Documents\----\ -----\ Ball - BEST directory
Ball = pwd;
% Ball = 'C:\----\--\Documents\----\ -----\ Ball - BEST'
Upvotes: 1
Reputation: 60574
Use fileparts
:
[p, fname, ext] = fileparts(p);
top = strcat(fname, ext);
This peels off the last folder from path p
in top
. The ext
must be preserved in case the folder name has a dot it it.
Upvotes: 2