Filter löschen
Filter löschen

up one directory's folder name from current directory

67 Ansichten (letzte 30 Tage)
venkat ta
venkat ta am 25 Aug. 2020
Beantwortet: Image Analyst am 25 Aug. 2020
I have directory path below
/Volumes/GoogleDrive/Shared /Mesure_geo/Temp/delete/AGING/LKG0.3V'
I need to get two string variables
LKG0.3V
AGING
yes I wanna use the current folder name and previous folder name (up one directory to AGING) in MatLab

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Aug. 2020
See my utility:
%==========================================================================================================================
% Gets the folder one level up. If startingFolder is a filename with an extension it gets the containing folder and the child folder is null.
% Returns null for both if the folder does not exist, and it's not a filename either.
function [parentFolder, childFolder] = GetParentFolder(startingFolder)
parentFolder = []; % Initialize
childFolder = [];
try
if isfolder(startingFolder)
[parentFolder, childFolder, ext] = fileparts(startingFolder);
% Need to append extension for rare cases where deepest folder has a dot in the name.
childFolder = [childFolder, ext];
elseif isfile(startingFolder)
% It's a filename, not a folder. Need to change otherwise childFolder will be returned as the base file name.
[parentFolder, childFolder, ext] = fileparts(startingFolder);
childFolder = []; % No child folder since it's a filename, not a folder name.
end
catch ME
message = sprintf('Error in GetParentFolder():\n%s', ME.message);
uiwait(msgbox(message));
end
return; % from GetParentFolder
end

Weitere Antworten (0)

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by