ThermoRestart
ThermoRestart

Reputation: 27

MATLAB - Save last Folder in Path as a character String? (Syntax)

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

Answers (2)

Pablo
Pablo

Reputation: 115

You can use the UNIX command "pwd"

% On C:\----\--\Documents\----\ -----\ Ball - BEST directory
Ball = pwd;
% Ball = 'C:\----\--\Documents\----\ -----\ Ball - BEST'

Upvotes: 1

Cris Luengo
Cris Luengo

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

Related Questions